perf(server): cache App Router route wiring plans#2179
Open
NathanDrake2406 wants to merge 4 commits into
Open
Conversation
App Router SSR repeatedly rebuilds route-invariant layout, template, error, and slot wiring metadata while constructing each page response. That work is unnecessary for generated route objects that are stable for the lifetime of the server process. Cache the derived wiring plan per route object and keep per-request work focused on params, dependency barriers, and React element construction. Also avoid template and slot dependency allocations on routes that do not use those features.
commit: |
Contributor
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
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.
Overview
WeakMapkeyed by the generated route object.packages/vinext/src/server/app-page-route-wiring.tsxbuildAppPageElementsself-time on warm SSR requests.Why
Generated App Router route objects are stable for the server process, but the SSR path rebuilt derived layout, template, error, tree-position, and slot metadata for every request. Those derivations are route-invariant, while params and render dependencies remain request-scoped.
Profiling
Warm SSR profile of
benchmarks/vinextat/, built with--sourcemap --minify false, using 1000 warmup requests plus 20000 measured requests.buildAppPageElementsself-timeapp-page-route-wiringsource self-timeCPU self-time is the primary signal here. HTTP timing is included as supporting context only.
Validation
Commands run
The final pre-commit hook also ran staged
vp check --fix, full check, and knip.Risk / Compatibility
Notes
WeakMap, so route objects can still be collected if a dev/runtime graph drops them.