Perf: Eliminate double normalization of params in callParts#21318
Merged
NullVoxPopuli merged 1 commit intoemberjs:mainfrom Apr 17, 2026
Merged
Perf: Eliminate double normalization of params in callParts#21318NullVoxPopuli merged 1 commit intoemberjs:mainfrom
NullVoxPopuli merged 1 commit intoemberjs:mainfrom
Conversation
callParts() was normalizing all parameters twice — once to calculate paramLoc via SpanList.range(), then again to build the positional args. The paramList computed on the first pass is already ASTv2.ExpressionNode[] and can be passed directly to builder.positional(). Safe because: - Symbol allocations (allocateFree/allocateNamed) are idempotent — they check indexOf/cache before allocating, so the second pass was pure waste. - PositionalArguments stores exprs as readonly — no mutation concern. - SpanList.range() only reads .loc from the nodes — no stored references. The duplication dates back to the original 2020 commit (8e11b91) where paramList was computed for SpanList.range() but then not reused for the builder, with an identical .map(normalize) call created instead. Impact (pnpm bench:precompile, prod dist, Apple M1 Max): - normalize large (33374c): 18.92ms → 17.72ms (6%) - precompile large: 43.01ms → 41.12ms (4%)
This was referenced Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eliminates redundant work in
packages/@glimmer/syntax/lib/v2/normalize.ts. Parser-independent — works with current Jison pipeline.The fix
callParts()was normalizing all parameters twice — once to calculateparamLocviaSpanList.range(), then again to build the positional args. TheparamListfrom the first pass is alreadyASTv2.ExpressionNode[]and can be passed directly tobuilder.positional().The duplication dates back to the original 2020 commit where
paramListwas computed at line 228 but not reused at line 234, with an identical.map(normalize)call created instead.Why it's safe: symbol allocations (
allocateFree/allocateNamed) are idempotent (indexOf/cache check before allocating),PositionalArgumentsstores exprs asreadonly, andSpanList.range()only reads.locfrom the nodes.Where the savings come from:
callParts()is called once per helper/component invocation that has params —{{helper a b}},{{#if cond}},(subexpr a), etc. Plain path expressions like{{this.name}}don't go throughcallPartsand are unaffected. The benchmark fixture has 12 param-bearing invocations per ~1.5k chars (36% of all mustaches), which is representative of a typical route template with moderate interactivity. Templates with higher helper/sub-expression density will see larger gains.Benchmark (
pnpm bench:precompile, averaged over 5 paired runs)Apple M1 Max, Node 24.14.
Prod build
Dev build
Dev build shows a larger improvement because the redundant normalization also triggers DEBUG assertions (e.g. the
charPosForround-trip check) that are eliminated along with the duplicate pass.Reproduce:
pnpm build && pnpm bench:precompile