-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor(router-core): interpolatePath can cache the parsed path template #5874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe PR exports the Changes
Sequence DiagramsequenceDiagram
participant Router as RouterCore
participant Path as interpolatePath
participant Cache as LRU Cache
participant Helper as forEachSegment
Router->>Path: interpolatePath(path, options + cache)
Path->>Helper: forEachSegment(path, cache, callback)
loop For each segment in path
Helper->>Cache: lookup(segmentKey)
alt Cache Hit
Cache-->>Helper: ParsedSegment (cached)
else Cache Miss
Helper->>Helper: parse segment
Helper->>Cache: store(segmentKey, ParsedSegment)
Cache-->>Helper: ParsedSegment (stored)
end
Helper->>Helper: invoke callback with ParsedSegment
end
Helper-->>Path: completed
Path-->>Router: interpolated result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings📚 Learning: 2025-10-01T18:30:26.591ZApplied to files:
🧬 Code graph analysis (2)packages/router-core/src/router.ts (1)
packages/router-core/src/path.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (8)
Comment |
|
View your CI Pipeline Execution ↗ for commit 6175fe2
☁️ Nx Cloud last updated this comment at |
|
what's the bundle size impact here? |
I haven't measured (do we have something to measure that?) but yeah that was my blocker too: the perf gains don't really seem worth it here for the increase in code. |
We can squeeze a little more performance out of
interpolatePathby caching the parsed representation of the template path to avoid having to callparseSegmentagain on repeated interpolations of the same path.Cache is keyed on the
pathand not theparams, so it should have a pretty good hit rate.This function is not very slow (~1-2MHz), but it is called on
buildLocationandmatchRoutesInternal(2 hot paths). But I'm not sure this change is worth the 1.4x we get out of it...bench: 1.4x
Summary by CodeRabbit
New Features
Performance Improvements