Skip to content

fix(tech-detect): choose every bundle's hint windows before any remainder or tail takes page budget #1445 - #1453

Closed
nc9 wants to merge 1 commit into
mainfrom
fix/page-budget-hint-first-1445
Closed

nc9 wants to merge 1 commit into
mainfrom
fix/page-budget-hint-first-1445

Conversation

@nc9

@nc9 nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1445.

With the page budget full (512 KB in the cloud), a small early script's whole remainder used room that a later bundle's windows around its vendor literal needed.

  • createBundleSampler(content, headChars) (new, packages/tech-detect/src/bundle-sample.ts) classifies the body and finds the hint windows once, then answers sample(maxChars, windowsOnly). sampleBundleExtras is unchanged in behaviour (windows then tail).
  • buildTechInputs pass 2 (packages/audit-engine/src/technologies.ts) runs in steps over all of the page's bundles: windows only at 2 KB, 8 KB, then the full 24 KB per bundle, then the remainder or tail. A bundle's held windows are given back and re-chosen each step with the room left; the last step never drops windows a windows-only step chose.
  • The windows-only step leaves the tail its reserve too (min(6 KB, a quarter)), and the final step keeps the windows a windows-only step chose, so a window-heavy bundle still sends its tail.
  • Cost bound and fairness: the window search reads at most 12 MB of bundle text per page, shared by water-filling (windowScanAllowances): the smallest bundles first, each given its whole length when that is within an equal share of what is left, the rest sharing the remainder, at least 64 KB each. A bundle that does not fit its share is searched in the start of it (windows from that prefix, no tail), never skipped; a single huge body gets the whole 12 MB. The hint search and the lower-cased copy read only the searched prefix. A bundle is not scanned for windows when under 420 bytes of room is left, but the last step still scans for a tail of 32 bytes or more.
  • Measured at the cloud caps on real minified bundles, N copies each with a unique tail, same harness, main vs this head (RSS in MB): 30 x 443 KB 75 ms vs 930 ms (122 vs 130); 30 x 1.5 MB 273 vs 765 (230 vs 310); 28 x 3.3 MB 8273 vs 1012 (337 vs 377); 20 x 3.3 MB 5867 vs 1039 (720 vs 598); 30 x 3.7 MB 2766 vs 1021 (733 vs 633). So a page of many mid-size scripts costs up to about 1 s instead of under 0.3 s; pages of multi-megabyte scripts are cheaper than on main. (An earlier revision of this PR said 8.2 s vs 1.55 s for the 28 x 3.3 MB case; the 8.2 s was main on this harness, and the reviewer measured about 1.2 s on theirs, so compare within one harness.)
  • Tests (tech-extras-budget-1420.test.ts and extras-budget-1420.test.ts): 25 scripts at the page cap with the loader in the last bundle's window; 21 scripts; a loader in an early small script's remainder still found; five window-heavy bundles then a late one (rounds); exact accounting; held room given back; a window-heavy bundle keeps its tail, at the sampler and at page level (8 KB of extras, reserve of 2 KB); the allowances (within the cap, small bundles whole, equal shares, a single huge body gets its share, a floor for 400 bundles); six 3 MB bundles with the loader 0.8 MB into the last; an 18 MB body with a loader 2 MB in; 40 bundles of 600 KB where a loader past the share is not searched; a tail under 420 bytes is sent; the sampler's scan prefix. Mutants that fail a test: no tail reserve in the windows step (sampler and page level), no 2 KB / 8 KB rounds, full charge instead of the delta, no give-back, no scan cap, no prefix passed to the sampler, the 420-byte rule applied to the tail. The sampler lives in a function, so there is no explicit clear to drop.
  • Comparison against main on 18 real bundles and 13 synthetic ones at three caps (123 cells, at the final head): 0 regressions, 1 gain. (An 8 MB cap lost a vendor in the 31-bundle page at 256 KB caps, so the cap is 12 MB.) The earlier "gains" were mostly the lost tail reserve and are gone with the fix. I did not run a corpus.
  • Docs paragraph and CHANGELOG (Unreleased / Fixed).

Skill: no change needed.

nik

@nc9
nc9 force-pushed the fix/page-budget-hint-first-1445 branch 2 times, most recently from 0f4c572 to 817c947 Compare October 31, 2026 19:12
…nder or tail takes page budget #1445

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/page-budget-hint-first-1445 branch from 817c947 to d4e0ba6 Compare October 31, 2026 19:59
@nc9 nc9 mentioned this pull request Oct 31, 2026
@nc9

nc9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tech-detect: allocate hint windows across all of a page's bundles before whole remainders (#1420 residual)

1 participant