Repository navigation
fix(core): keep SVG id renaming linear in the page size and within the render size limit - #8147
Conversation
…, caps and charges what it adds
…rges the bytes it adds
terencecho
left a comment
There was a problem hiding this comment.
Reviewed pinned head eca3cb02e32f3c69b332a14b13d35b4971502b38.
[P2] Compute the sanitized/hash prefix once per scope, before minting its IDs (svgIdNamespacing.ts, mintNamespacedId / planRenames). mintNamespacedId calls sanitizeNamespaceSegment(namespace) for every renamed ID. With a namespace over 48 characters, each call scans the entire namespace with replace and FNV-1a. The output prefix is capped, but compile work remains O(namespace length × renamed ID count), even though that namespace appears only once in the mount's input. These scans all happen in planning before the first generated-byte charge can reject the page.
A deterministic regression probe using two mounts, 200 colliding/referenced SVG IDs and one 5,000-character namespace recorded 200 full FNV-1a calls (1,000,000 character iterations), rather than one hash for that scope. A longer composition ID and more IDs amplify this while the emitted prefixes stay small enough not to trip the new output budget. Please cache/precompute each scope's prefix and add a regression that counts work across many IDs under one long namespace.
The shared rename table and per-selector ID lookup remove the two table-copy costs, and the added attribute/stylesheet charging is wired to the producer's budget. The declared separate follow-up for reference-alias selector work is not this finding.
Validation: full workspace build passed; 95 focused core SVG namespacing, selector-token and inlining tests plus 20 producer size-limit tests passed. The additional hash-count regression fails (200 vs at most 1); it was removed and the original core tests passed again. Required failing-test lines are present. CI was still running, with no failed checks at inspection. No render/browser benchmark performed.
— tai (automated review)
terencecho
left a comment
There was a problem hiding this comment.
Re-reviewed at 7d0998c. My P2 is resolved: planRenames caches each mount's sanitized prefix before minting its ids, so a 5,000-character namespace is hashed once for 200 renamed ids. Collision suffixing and namespace output remain unchanged. The two regenerated page goldens contain only minifier symbol renames.
Validation: full workspace build passed; 100 focused core tests (including both page goldens) and 20 producer size-limit tests passed. Restoring the old implementation makes the new work-count regression fail with 200 hash calls instead of one; restoring the fix passes. The required fails-without-the-fix test lines are present. CI is still running, with no failed checks at submission. No remaining blocker found in this re-review.
— tai (automated review)
Edit accuracy: accurate 271 (base branch 271), smooth 62 of thoseThe gate passes. Quarantined, measured but not gated (0) |
What
Compiling a page whose mounted compositions repeat SVG ids now takes time and memory in line with the page's size, and what it adds counts toward the render's size limit.
<the whole composition id>--<id>, so a very longdata-composition-idlengthened every renamed id and every reference to it. A composition id over 48 characters now becomes its first 32 characters and a hash of the whole, and each mount's ids stay distinct. Ordinary ids are renamed exactly as before.COMPOSITION_TOO_LARGEinstead of running out of memory.Why
When two mounted compositions use the same SVG id and something references it natively (
url(#id),href="#id"), the compiler renames one of them.namespaceCollidingSvgIdsreturned one map per mount, and each map copied the page-wide table of inherited renames, so memory and time grew as mounts × ids.rewriteSvgIdReferencesInCssturned the whole map into a list for every selector. Neither the renamed ids nor the stylesheet growth was charged to the size budget the compiler already keeps for mounts.Related work
None.
How
svgIdNamespacing.ts: each mount gets aScopedIdMap, its own renames read over the one shared page table. Ids the mount defines itself still hide the shared entry, as the copied map did. Callers read it throughget,hasandsize, the only parts they used.rewriteSvgIdReferencesInCssreads the#ids a selector names (selectorIdTokens, the same readingreplaceSelectorIdTokensdoes) and looks each up.sanitizeNamespaceSegmentcaps the prefix, hashing with the FNV-1a functioncanary.tsalready had, now exported. The existing used-id suffix keeps the result unique.namespaceCollidingSvgIdstakes an optionalcharge(scopeIndex, bytes), called after each element with the attribute bytes it added.inlineSubCompositionswires it, and the stylesheet growth, tochargeEmittedunder the mount's own file, which the producer charges to its expansion budget.svg-selector-aliases-inline.tsis regenerated, since it bundlesselectorIdTokens.ts.Not changed:
rewriteSvgSelectorsstill builds its reference targets from every recorded alias once per selector. That is bounded by one mount's own input, and a follow-up PR will fix it.Test plan
packages/core/src/compiler/svgIdNamespacing.test.ts, the first commit:packages/core/src/compiler/inlineSubCompositions.test.ts.packages/corecompiler and runtime pass all 4,045 tests;htmlCompiler.sizeLimit.test.tsin the producer passes 15 of 15;svg-selector-aliases-inline.tsregenerates identical to the committed file at main's source, and to this branch's at the fix.