Repository navigation
perf(router): try templates with an index loop - #452
Conversation
for...of destructuring each template child costs more than reading it by index, as find already does for catch-alls, and the segment is read once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VVaw7NfvMWthzxzRb81nfW
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 41 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — a behavior-preserving micro-optimization that matches the existing catchAlls index-loop pattern in find.
Reviewed changes
findTemplateindex loop — replaces thefor...of+ destructuring with an index loop and hoistsconst segment = segments[index]!out of it, somatchesTemplateandfindreadtemplates[i]!directly.- Semantics — iteration order and per-element work are unchanged;
segmentsis not mutated during matching andnode.templatesis only appended to during insertion, so the hoisted segment and live array reads cannot diverge from the old behavior. - Tests —
pnpm vitest run packages/routerpasses (7 files, 75 tests), includingtemplates.test.ts.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
Merging this PR will not alter performance
Comparing Footnotes
|

🤖 Generated with Claude Code
https://claude.ai/code/session_01VVaw7NfvMWthzxzRb81nfW
What
findTemplatedestructured each template child in afor...ofloop and readsegments[index]on every pass. It now reads the children by index, the wayfindalready reads catch-alls, and reads the segment once.Cost (vs main 78a428a)
min+gzip: 2,529 → 2,527 B (-2).
Steady instructions per match (callgrind, hash seeds 1 and 2, the 500-route template set from perf(router): check templates without slicing the value #451):
v{v}hit, after the other templates missCold start (cold3, callgrind) on rpc10, rest10 and tpl10 is within ±0.2%.
Checks
Generated by Claude Code