Give RouteCacheEntry a single hidden class across its lifecycle#96164
Merged
Conversation
acdlite
force-pushed
the
deopt-explorer-tooling
branch
2 times, most recently
from
July 24, 2026 19:40
f1aa52a to
dcb9d1e
Compare
acdlite
force-pushed
the
deopt-fix-route-entry-shape
branch
from
July 24, 2026 19:47
58c1258 to
336e957
Compare
Contributor
Tests PassedCommit: 0856011 |
Contributor
Stats from current PR🟢 1 improvement
📊 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: 0856011 |
acdlite
force-pushed
the
deopt-fix-route-entry-shape
branch
from
July 24, 2026 19:57
336e957 to
0856011
Compare
acdlite
marked this pull request as ready for review
July 24, 2026 20:14
samselikoff
approved these changes
Jul 24, 2026
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
RouteCacheEntryobjects cycled through three hidden classes over their lifecycle, found by runningpnpm bench:deopt --scenario segment-cache: (A) the pending object literal increateDetachedRouteCacheEntry, which did not declarehasDynamicRewrite; (B) that shape plushasDynamicRewriteappended post-construction byfulfillRouteCacheEntry, a shape transition that also deprecates the original map; and (C) the two fulfilled-entry literals (deprecated_requestOptimisticRouteCacheEntryincache.tsand the synthetic entry inmatchKnownRouteinoptimistic-routes.ts) which declarehasDynamicRewritein a different key position, betweensupportsPerSegmentPrefetchingandrenderedSearch. Every property access on a route cache entry in the hot navigation/prefetch paths was therefore polymorphic.This PR pre-declares
hasDynamicRewrite: falseincreateDetachedRouteCacheEntryat the same key position as the fulfilled literals, collapsing all three shapes into one hidden class, and moves thehasDynamicRewrite: booleantype declaration fromFulfilledRouteCacheEntrytoRouteCacheEntrySharedto match. ThefulfilledEntry.hasDynamicRewrite = falsestore infulfillRouteCacheEntryis left in place; it is now an in-place store rather than a shape transition, and it re-clears the flag on re-fulfillment.Behavior neutrality
The field is pre-initialized to
falseon pending/empty entries and semantics are identical: no runtime code readshasDynamicRewritefrom an unfulfilled entry, and there are noinchecks,Object.keys, ordeleteoperations on these entries — only property reads.pnpm --filter=next typespasses with the field declared on the shared type.Verification
Measured with
pnpm bench:deopt --scenario segment-cache(fixture force-rebuilt against the patched build). ThehasDynamicRewritepolymorphic IC cleared, along with ~24 entry-field polymorphic IC lines acrossnavigation.ts,optimistic-routes.ts,scheduler.ts, andcache.ts(status, tree, canonicalUrl, renderedSearch, metadata, couldBeIntercepted, supportsPerSegmentPrefetching, staleAt, version, size). Totalic-polymorphicfindings dropped from 84 lines to 60. Results were confirmed stable across a second run.Before/after
findings.txtdiff:Two high-severity
wrong maplines remain and are explicitly NOT claimed by this PR: thecache-map.tsisValueExpiredline reads the intentionally 3-typed route|segment|bfcache map-value union, and theoptimistic-routes.tsresidual (now attributed to thehasDynamicRewriteread at 791:26) is a one-time map-deprecation deopt caused by in-place fulfillment generalizing null-initialized field types. The latter is tracked separately with a possible follow-up that fulfills entries via fresh literals instead of mutation.Tests
test/e2e/app-dir/segment-cache/optimistic-routing-rewrite-detection-regression(test-start-turbo): 3 passedtest/e2e/app-dir/segment-cache/staleness(test-start-turbo): 4 passed, 5 skipped (mode skips)Note on base branch