docs(perf): preserve source-bound static encoding measurements
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"sourceCommit": "eb2538772e1bfabbeb291e4a5efa177c79074de1",
|
||||
"sourceGitBlobSha256": {
|
||||
"job-tracker-ui/package.json": "8b31e44c10b77b6d1e007af04c757c0577f12972ff3f6c7079bbc4c446a0d415",
|
||||
"job-tracker-ui/package-lock.json": "ac90fbdc79e2e0f23d54748814b41a03f5dcaf8fd27291b3dcb73b2603a83e72",
|
||||
"job-tracker-ui/next.config.js": "2bbcc9d6093d6f263114f4992fd9c77a6172f0602deb92bf7163823ba58b1757",
|
||||
"job-tracker-ui/app/layout.tsx": "d2e460998e4182f11657089850f9144059f453ebd9c4d1fbcd3f6aee25449843"
|
||||
},
|
||||
"nativeReceipts": [
|
||||
{
|
||||
"path": "measure-static-encoding.mjs.txt",
|
||||
"canonicalSha256": "b700120c790f4ec50f125ade040b82044ccbc79a5d0142885d7a34910762b682",
|
||||
"rawSha256": "b700120c790f4ec50f125ade040b82044ccbc79a5d0142885d7a34910762b682",
|
||||
"gzipSha256": "020bb4bc3445a426f8757b9268b8b3b62e1ddbc8d8961d8a35c511840c7cb7d5",
|
||||
"nativeEncoding": "utf-8-sig"
|
||||
},
|
||||
{
|
||||
"path": "static-encoding.json",
|
||||
"canonicalSha256": "a5ba46dcad650f8de1bbadcb5f77331ed3f40fc05058f5c79d347471b654a25b",
|
||||
"rawSha256": "a5ba46dcad650f8de1bbadcb5f77331ed3f40fc05058f5c79d347471b654a25b",
|
||||
"gzipSha256": "941f8e1bb95196a1c3dd2341623a2f4fd7a79460395afab34562aba14712bcd9",
|
||||
"nativeEncoding": "utf-8-sig"
|
||||
},
|
||||
{
|
||||
"path": "static-encoding.txt",
|
||||
"canonicalSha256": "8ae1d675b5874c82ddf4cc0e4a4e7351822f293953ec8338034d3cc3736fefa1",
|
||||
"rawSha256": "1171e4f98ed0c9eac50f6b1f71c6f643e6e324c4c29aba6ac868e7d7a3717ccd",
|
||||
"gzipSha256": "5efc6aaf111bfec3478589d5d6d5ced531623a40d41c07408f233b9be84053b7",
|
||||
"nativeEncoding": "utf-16"
|
||||
}
|
||||
],
|
||||
"scope": "Frozen offline export census/encoding only, not current runtime or deployed transfer"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import crypto from 'node:crypto';
|
||||
import os from 'node:os';
|
||||
import assert from 'node:assert/strict';
|
||||
import { performance } from 'node:perf_hooks';
|
||||
import { gzipSync, gunzipSync, brotliCompressSync, brotliDecompressSync, constants } from 'node:zlib';
|
||||
const [exportPath, output] = process.argv.slice(2);
|
||||
const root = path.resolve(exportPath);
|
||||
const sha = bytes => crypto.createHash('sha256').update(bytes).digest('hex');
|
||||
function walk(dir) { return fs.readdirSync(dir, { withFileTypes: true }).flatMap(e => e.isDirectory() ? walk(path.join(dir, e.name)) : [path.join(dir, e.name)]); }
|
||||
const entries = walk(root).filter(name => /\.(?:js|css|html|svg)$/.test(name)).sort();
|
||||
assert.ok(entries.length > 0);
|
||||
const median = values => [...values].sort((a,b)=>a-b)[Math.floor(values.length/2)];
|
||||
const files = entries.map(name => {
|
||||
const raw = fs.readFileSync(name), relative = path.relative(root, name).replaceAll('\\', '/');
|
||||
const gzipTimes = [], brotliTimes = [];
|
||||
let gzip, brotli;
|
||||
for (let repetition=0; repetition<3; repetition++) {
|
||||
let start = performance.now(); gzip = gzipSync(raw, { level: 6 }); gzipTimes.push(performance.now()-start);
|
||||
start = performance.now(); brotli = brotliCompressSync(raw, { params: { [constants.BROTLI_PARAM_QUALITY]: 5 } }); brotliTimes.push(performance.now()-start);
|
||||
assert.deepEqual(gunzipSync(gzip), raw); assert.deepEqual(brotliDecompressSync(brotli), raw);
|
||||
}
|
||||
return { path: relative, sha256: sha(raw), rawBytes: raw.length, gzip6Bytes: gzip.length, brotli5Bytes: brotli.length, gzipMilliseconds: gzipTimes, brotliMilliseconds: brotliTimes, gzipMedianMilliseconds: median(gzipTimes), brotliMedianMilliseconds: median(brotliTimes) };
|
||||
});
|
||||
const sum = group => ({ files: group.length, rawBytes: group.reduce((n,x)=>n+x.rawBytes,0), gzip6Bytes: group.reduce((n,x)=>n+x.gzip6Bytes,0), brotli5Bytes: group.reduce((n,x)=>n+x.brotli5Bytes,0) });
|
||||
const html = fs.readFileSync(path.join(root, 'index.html'), 'utf8');
|
||||
const scriptPaths = [...new Set([...html.matchAll(/<script\b[^>]*\bsrc="([^"]+)"[^>]*>/g)].map(m=>m[1].split('?')[0].replace(/^\//,'')))];
|
||||
assert.ok(scriptPaths.length > 0);
|
||||
const indexScripts = files.filter(f=>scriptPaths.includes(f.path));
|
||||
assert.equal(indexScripts.length, scriptPaths.length);
|
||||
const report = { source: 'eb2538772e1bfabbeb291e4a5efa177c79074de1', environment: { node: process.version, platform: process.platform, architecture: process.arch, cpu: os.cpus()[0].model }, buildApiBase: 'http://localhost:5302/api', indexSha256: sha(Buffer.from(html)), repetitions: 3, summaries: { javascript: sum(files.filter(x=>x.path.endsWith('.js'))), css: sum(files.filter(x=>x.path.endsWith('.css'))), svg: sum(files.filter(x=>x.path.endsWith('.svg'))), html: sum(files.filter(x=>x.path.endsWith('.html'))), declaredIndexScripts: sum(indexScripts) }, sourceMaps: walk(root).filter(name=>name.endsWith('.map')).length, files, limits: ['Offline warm-file compression cost and content sizes only; excludes HTTP headers/TLS/network', 'No nginx/CDN/API compression configuration or production change', 'Complete export inventory is not a route request budget; root declared scripts exclude later dynamic imports', 'Three local repeats do not establish field latency, server throughput or deployed encoding'] };
|
||||
fs.writeFileSync(output, JSON.stringify(report, null, 2)+'\n');
|
||||
console.log(JSON.stringify({ summaries: report.summaries, sourceMaps: report.sourceMaps, verifiedRoundTrips: files.length * 3 * 2 }));
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1 @@
|
||||
{"summaries":{"javascript":{"files":58,"rawBytes":3674509,"gzip6Bytes":1089362,"brotli5Bytes":1015470},"css":{"files":2,"rawBytes":3958,"gzip6Bytes":1189,"brotli5Bytes":1073},"svg":{"files":4,"rawBytes":28397,"gzip6Bytes":6971,"brotli5Bytes":6404},"html":{"files":3,"rawBytes":32504,"gzip6Bytes":8339,"brotli5Bytes":7486},"declaredIndexScripts":{"files":7,"rawBytes":582094,"gzip6Bytes":178820,"brotli5Bytes":169211}},"sourceMaps":0,"verifiedRoundTrips":402}
|
||||
Binary file not shown.
Reference in New Issue
Block a user