Keep optimistic-route param handling monomorphic#96169
Merged
Merged
Conversation
Normalize ResolvedParams values to strings at the resolution boundary
(join catch-all parts at set time) and replace split('/')+filter with a
manual splitter that always produces packed-elements arrays. This
removes the wrong-map deopts in reifyRouteTree and matchKnownRoutePart
caused by the string|string[] union and V8's packed/holey elements-kind
instability propagating through slice/join.
Contributor
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (10 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsfailed to diffapp-page-exp..time.prod.jsDiff too large to display app-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsDiff too large to display app-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsfailed to diffpages-api-tu..ntime.dev.jsDiff too large to display pages-turbo...ntime.dev.jsDiff too large to display 📎 Tarball URLCommit: 69bcd20 |
Contributor
Tests PassedCommit: 69bcd20 |
acdlite
marked this pull request as ready for review
July 24, 2026 20:38
samselikoff
approved these changes
Jul 24, 2026
acdlite
enabled auto-merge (squash)
July 24, 2026 20:52
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.
Found by
pnpm bench:deopt --scenario segment-cache(V8 deopt/IC analysis of the client segment cache), with map-level IC evidence. Two related sources of megamorphism in the optimistic route matching path: (1)String.prototype.splitreturns arrays whose elements kind alternates between PACKED_ELEMENTS and HOLEY_ELEMENTS depending on internal fast paths, andfilter/slicepropagate the kind, so the arrays flowing throughmatchKnownRoutePartandreifyRouteTreehad unstable maps, causing repeated "wrong map" eager deopts at theslicesite inmatchKnownRoutePartand thejoinsite inreifyRouteTree(which runs once per tree node on every optimistic match); and (2) the privateResolvedParamsmap typed asMap<string, string | string[]>forced a polymorphicArray.isArray/joinbranch on every dynamic segment during reification.Semantics are preserved exactly. Catch-all param values are now joined into a single string at the moment they are resolved in
matchKnownRoutePartinstead of at read time inreifyRouteTree— the value was only ever read once and immediately collapsed to a joined string cache key, and the empty optional catch-all case writes'', which is identical to[].join('/'). The newsplitPathnameIntoPartshelper is byte-for-byte equivalent topathname.split('/').filter((p) => p !== ''): empty tokens from leading, trailing, or consecutive slashes are skipped, but the parts array is built by pushing into an array literal so it always has a packed elements kind.Before/after
findings.txtdiff from the bench scenario:Both high-severity wrong-map deopts in
optimistic-routes.tsare gone (confirmed across two independent after-runs); the remaining new lines are info-level string-receiver ICs inside the splitter helper. Total ic-polymorphic findings dropped from 90 to 80.Tests (all passing,
test-start-turbo):test/e2e/app-dir/segment-cache/optimistic-route-cache-keying-regression— 1 passedtest/e2e/app-dir/segment-cache/optimistic-routing-parallel-slot-catchall-regression— 1 passedtest/e2e/app-dir/segment-cache/encoded-slash-params— 2 passed