perf(router-core): hoist regex literals evaluated per built location - #8425
schiller-manuel wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change hoists regular expressions in router path, location, and URL utility code to module-level constants. It also changes the ChangesRouter core optimization and comparison updates
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~15 minutes Change: Refactor Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change is ready to merge; no concrete user-facing correctness or reliability risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
|
View your CI Pipeline Execution ↗ for commit 2ad9de3
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview4 package(s) bumped directly, 19 bumped as dependents. 🟩 Patch bumps
|
Bundle Size Benchmarks
The following scenarios have bundle-size changes compared with the baseline:
Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better. |
Merging this PR will degrade performance by 5.03%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | mem client unique-location-churn (vue) |
2 MB | 2.1 MB | -5.03% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing codex/hoist-hot-regex (2ad9de3) with main (83895f1)
A regex literal creates a new RegExp object every time it is evaluated (measured: 56 B per evaluation, 0 once hoisted). decodePath and encodePathLikeUrl run on every buildLocation, cleanPath on every href of a basepath router, encodeParam on every splat and trimPathRight on every trailing-slash path; parseLocation's fast-path test runs per navigation. Their literals are now module constants. trimPathLeft (construction only) and the cold branches of getUrlScheme are left as they were. Allocation per buildLocation (sampling heap profiler over 160k builds against the production dist, Node 24.8; on top of the previous commit): relative destination 1309 -> 1197 B (-112) search updater 1085 -> 969 B (-116) static destination 955 -> 786 B (-169) CPU (tests/build-location.bench.ts, two rounds, hz): within noise, directionally +1-2%: search updater 41.6k/44.2k -> 43.5k/43.2k, relative 29.8k/30.2k -> 29.6k/30.3k, masked 20.5k/20.9k -> 20.8k/20.6k. Bundle: react-router.minimal +18 gzip (derived from the composed measurements 86077 with, 86059 without these hoists). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 72b093cad28641112858bfbc9140175eb2c1a3da)
d31406c to
2ad9de3
Compare
🎯 Changes
A regex literal creates a new RegExp object every time it is evaluated
(measured: 56 B per evaluation, 0 once hoisted). decodePath and
encodePathLikeUrl run on every buildLocation, cleanPath on every href of a
basepath router, encodeParam on every splat and trimPathRight on every
trailing-slash path; parseLocation's fast-path test runs per navigation.
Their literals are now module constants. trimPathLeft (construction only)
and the cold branches of getUrlScheme are left as they were.
Allocation per buildLocation (sampling heap profiler over 160k builds against
the production dist, Node 24.8; on top of the previous commit):
relative destination 1309 -> 1197 B (-112)
search updater 1085 -> 969 B (-116)
static destination 955 -> 786 B (-169)
CPU (tests/build-location.bench.ts, two rounds, hz): within noise,
directionally +1-2%: search updater 41.6k/44.2k -> 43.5k/43.2k, relative
29.8k/30.2k -> 29.6k/30.3k, masked 20.5k/20.9k -> 20.8k/20.6k.
Bundle: react-router.minimal +18 gzip (derived from the composed measurements
86077 with, 86059 without these hoists).
Verification on
maintest:unit(3252 passed),test:types,test:eslintbuildLocationcalls against the productiondist/esm(56 B per regex-literal evaluation measured in isolation, 0 once hoisted); CPU numbers from the benchmark in test(router-core): add a Link-like buildLocation benchmark #8423.Relationship to other PRs
Independent. Benchmark: #8423.
✅ Checklist
🚀 Release Impact
Summary by CodeRabbit
Performance
Bug Fixes
Release