count the responses kit inlines past 32 KB, and name each repo's biggest, so a page that carries a whole payload shows in the summary
Signed-off-by: dawn <90008@klbr.net>
48 unmodified lines4950515253545556575859606148 unmodified lines else if (page > 1 && routeOf(pathname) !== null) found.add(pathname); } return found;};
// kit inlines every response a page's loads read; past this one is a payload the page should// have trimmed or shared, so the summary counts itexport const INLINE_CAP = 32 * 1024;const INLINED = /<script type="application\/json" data-sveltekit-fetched data-url="\/xrpc\/([^?"]+)[^>]*>(.*?)<\/script>/gs;
/** the inlined responses of a page past INLINE_CAP, by nsid and size */export const inlinedOverCap = (html) => [...html.matchAll(INLINED)].filter((m) => m[2].length > INLINE_CAP).map((m) => ({ nsid: m[1], bytes: m[2].length }));198 unmodified linesExpand all199200201202203203204205206207143 unmodified linesExpand all198 unmodified linesExpand all activeFamilies.add(familyOf(plan)); return plan; }; // workers: the processes the render started, so each one past --workers is a recycle const totals = { rendered: 0, kept: 0, dropped: 0, over_budget: 0, pages: 0, bytes: 0, reads: 0, workers: 0 }; const totals = { rendered: 0, kept: 0, dropped: 0, over_budget: 0, pages: 0, bytes: 0, reads: 0, workers: 0, inlined_over_cap: 0 }; const failures = []; await Promise.all( Array.from({ length: workers }, () => runWorkerLoop(children, queue, takePlan, activeFamilies, familyOf, { hookPath, out, budget, totals }, async (plan, result, wallMs) => {143 unmodified linesExpand all4 unmodified lines56789910111213217 unmodified linesExpand all2312322332342352362372382392402414 unmodified linesimport { test } from "node:test";import { collectClients, keepClient } from "./client.mjs";import { fileOf, keyOf, keyOfUrl, prefixOf } from "./common.mjs";import { countsChanged, dirtyPages, readDiff } from "./diff.mjs";import { canonicalHtml, linksOf } from "./html.mjs";import { canonicalHtml, INLINE_CAP, inlinedOverCap, linksOf } from "./html.mjs";import { latestPath, maskShared, sharedNamed, sharedOf, sharedPath } from "./shared.mjs";
test("keyOf sorts params, drops empty ones and matches a request url", () => { assert.equal(keyOf("org.tangled.git.getTree", { ref: "main", repo: "did:plc:a", path: "" }), "org.tangled.git.getTree?ref=main&repo=did:plc:a");217 unmodified linesExpand all assert.equal(await collectClients(out, new Set(["a", "b"])), 0); assert.equal(await collectClients(out, new Set(["b"])), 1); assert.deepEqual([await kept("entry/app.A.js"), await kept("entry/app.B.js"), await kept("chunks/x.js")], [false, true, true]);});
test("a page's inlined responses past the cap are named with their size", () => { const inlined = (nsid, body) => `<script type="application/json" data-sveltekit-fetched data-url="/xrpc/${nsid}?repo=did%3Aplc%3Ax">${body}</script>`; const big = "x".repeat(INLINE_CAP + 1); const html = inlined("org.tangled.git.getTree", big) + inlined("org.tangled.git.getBlob", "small") + `<script type="application/json" data-diff>${big}</script>`; assert.deepEqual(inlinedOverCap(html), [{ nsid: "org.tangled.git.getTree", bytes: INLINE_CAP + 1 }]);});7 unmodified lines891011121213141516298 unmodified linesExpand all315316317318319319320321322323324175 unmodified linesExpand all500501502503504505506507508509510511142 unmodified linesExpand all65465565665765865966066166273 unmodified lines7 unmodified linesimport { parseArgs } from "node:util";import { gzipSync } from "node:zlib";import { rankOf } from "./budget.mjs";import { atomicJson, fileOf, keyOfUrl, ownerFiles, PAGE_QUERY, prefixOf, readJson, RENDERER_FORMAT, tokenOf, unpublishOwner } from "./common.mjs";import { canonicalHtml, linksOf } from "./html.mjs";import { canonicalHtml, inlinedOverCap, linksOf } from "./html.mjs";import { COUNTS, latestPath, ROUTES, SHARED_DIR, sharedNamed, sharedOf, sharedPath } from "./shared.mjs";
const { values: opts, positionals } = parseArgs({ allowPositionals: true,298 unmodified linesExpand all } return p; };
const stats = { rendered: 0, kept: 0, dropped: 0, over_budget: 0, render_ms: 0 }; const stats = { rendered: 0, kept: 0, dropped: 0, over_budget: 0, render_ms: 0, inlined_over_cap: 0 }; let inlinedMax = null; if (prior) { for (const route of Object.keys(pages)) { if (dirty.has(route)) continue; const to = fileFor(tmpDir, prefix, route);175 unmodified linesExpand all : [...linksOf(page.html, origin, (pathname) => routeOf(prefix, pathname, repo))]; const links = ( commitSourceSet.has(route) ? rawLinks : rawLinks.filter((next) => !next.startsWith(`${prefix}/commit/`)) ).map(intern); for (const inlined of inlinedOverCap(page.html)) { stats.inlined_over_cap++; if (!inlinedMax || inlined.bytes > inlinedMax.bytes) inlinedMax = { ...inlined, route }; } const canonical = canonicalHtml(page.html); const { shared, latest } = page; page = null; const gz = gzipSync(canonical, { level: 6, memLevel: 9 });142 unmodified linesExpand all reads: reads.count, read_ms: Math.round(reads.ms), ...stats, render_ms: Math.round(stats.render_ms), ...(inlinedMax && { inlined_max: inlinedMax }), heap_peak_mb: Math.round(heapPeak / 1_048_576), rss_mb: Math.round(process.memoryUsage().rss / 1_048_576), // the worker's peak since it started, so the repo it jumps on is the one that spiked max_rss_mb: Math.round(process.resourceUsage().maxRSS / 1024)73 unmodified lines