Store RouteTree slots in a Map to keep slot access monomorphic#96168
Merged
Conversation
Contributor
Stats from current PR🔴 2 regressions
📊 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.jsDiff too large to display app-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsDiff too large to display pages-api-tu..ntime.dev.jsDiff too large to display pages-turbo...ntime.dev.jsDiff too large to display 📎 Tarball URLCommit: 0cd6391 |
Contributor
Tests PassedCommit: 0cd6391 |
acdlite
marked this pull request as ready for review
July 24, 2026 20:35
samselikoff
approved these changes
Jul 24, 2026
acdlite
enabled auto-merge (squash)
July 24, 2026 20:51
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.
Root cause
Parallel route slot names are app-defined, so a
RouteTree.slotsstored as a plain object has an unbounded set of hidden classes: every distinct combination of slot names ({children},{children, side}, ...) produces a different shape. Keyed access over these objects makes the inline cache megamorphic. This was the singleic-megamorphicfinding reported bypnpm bench:deopt --scenario segment-cache, at the keyed store inconvertTreePrefetchToRouteTree(cache.ts:1531, keyschildren,side).This PR converts
RouteTree.slotsfrom{ [parallelRouteKey: string]: RouteTree }toMap<string, RouteTree>. All reads, writes, and iterations over RouteTree slots now go through monomorphicMapmethod calls, and iteration order is preserved (Map iterates in insertion order, matching plain-object string-key order).Scope
This was an approved design decision:
RouteTreeis an in-memory-only structure, so only it changes.CacheNode.slots(spread into JSX props) and the wire formats (TreePrefetch.slots,FlightRouterState[1]) remain plain objects; the existing conversion functions bridge them into and out of the Map.Before/after findings diff
The targeted finding at
cache.ts:1531is cleared. The remaining megamorphic site (stable across two runs) isscheduler.ts:1068:23inpingSharedPartOfCacheComponentsTree— the keyed loadoldTreeChildren[parallelRouteKey], whereoldTreeChildrenisFlightRouterState[1], i.e. the wire-format plain object that is intentionally out of scope for this change. That access existed before this PR; previously thefor...inloop key qualified the sibling load for V8's fast enum-cache path, and with Map iteration keys it now surfaces as a generic keyed load. Eliminating it would require changing theFlightRouterStatechildren format, which is a separate decision. The new info-level lines are one-time warm-up/prototype-registration deopts from the introducedMapusage, not steady-state IC misses.Tests
test/e2e/app-dir/segment-cache/basic(start-turbo): 10 passed, 1 skippedtest/e2e/app-dir/segment-cache/optimistic-routing-parallel-slot-catchall-regression(start-turbo): 1 passedtest/e2e/app-dir/segment-cache/cached-navigations(start-turbo): 16 passedpnpm --filter=next typespasses (also re-run after rebasing onto canary)