Repository navigation
refactor(router): lower the shared-parts count once per braced part - #201
Conversation
`expand` lowered `literals` in both the wait branch and the param branch.
Doing it once for every part starting with `{` covers both, and a literal
part starting with `{` only shares fewer parts with the next route.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VVaw7Sutbw6xMTMyDFeNfw
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Single-site
literalslowering —if (index < literals) { literals = index }moved from the wait branch and the param branch to one spot immediately afterif (segment[0] === '{'), so the shared-parts count drops once per braced part. - Comment update — the
shared/literalscomment now describes the rule as "the parts before the first part starting with{once decoded", which matches the code. - Behavioral delta — a literal part that starts with
{after decoding (e.g.{a.b}) now lowersliteralstoo. This is the one semantic change the PR calls out, and I verified it is safe: newliteralsis always ≤ old (lowering happens at a superset of indices), the count resets per route, and a smaller count only stops the next route's shared-prefix walk earlier, re-walking idempotentliteralChild/child.param ??=steps. The extraexpand(child.pending, …)those re-walks can trigger is a no-op, since the route that setliteralsalready flushed that region. A differential fuzz over{a.b}/%7Ba.b%7Dpermutations with late-add warmups (forcingwhole === trueand partial builds) found 0 mismatches, andlate-adds.test.ts:49already covers the duplicate{a.b}case.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Requested by dinwwwh · project thread
What
expandtracks how many of the previous route's parts the next route can reuse (literals). It used to lower that count in two places: once where a route waits, and once where it adds a param. Both happen only for a part that starts with{once decoded, so the count is now lowered in one place, right after that check.That check also catches a part such as
{a.b}, which starts with{but is literal text. The count now drops for that part too, so the next route shares fewer parts with this one and parses them again. Matching is unaffected. The comment onsharedandliteralsnow describes the rule this way.Measurements
Instruction counts from callgrind,
node --single-threaded, averaged over hash seeds 1 and 2:expandonly runs while the tree is being built, so steady-state matching does not change.Checks
if (true)mutant of the merged check is killed by the late-add test added in perf(router): make fewer calls per part when building the tree #195.Generated by Claude Code