Repository navigation
Avoid quadratic HMR queue shifts - #96137
Merged
Merged
Conversation
Contributor
Tests PassedCommit: 9df2c7c |
Contributor
Stats from current PR🔴 1 regression
📊 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
📎 Tarball URLCommit: 9df2c7c |
Co-Authored-By: Marcos Hernanz <[email protected]>
marcoshernanz
force-pushed
the
codex/perf-hmr-queue-index
branch
from
July 24, 2026 08:30
adeba4a to
a107ecb
Compare
Co-Authored-By: Marcos Hernanz <[email protected]>
bgw
approved these changes
Jul 25, 2026
marcoshernanz
marked this pull request as ready for review
July 25, 2026 00:34
m-kawafuji
pushed a commit
to m-kawafuji/next.js
that referenced
this pull request
Aug 8, 2026
## What - Replace repeated `Array.shift()` calls in the HMR affected-module breadth-first traversal with a monotonically increasing queue index. - Clear each consumed slot immediately so copied dependency chains can be collected during deep traversals. ## Why `getAffectedModuleEffects` can enqueue a wide set of parents when a shared dependency changes. Repeatedly shifting the queue moves the remaining array contents on every iteration, making broad invalidations increasingly expensive. Indexed reads keep traversal FIFO and make queue consumption linear. The slot clearing is important for deep graphs: it avoids retaining every processed item's copied `dependencyChain` until traversal returns. ## Benchmark Three independent 8-vCPU/16-GiB Vercel Sandbox workers ran Node.js 24.14.1 from exact commit `0950e8ae05db20c33302f02257114f5b857edabc`. The balanced `A1/B1/B2/A2` benchmark mirrors this loop for one changed shared dependency imported by N root modules, including dependency-chain allocation. Each phase used three warm-ups and nine samples. | Affected parents | `shift()` median | Indexed median | Improvement | Speedup | Worker agreement | Max baseline A/A drift | |---:|---:|---:|---:|---:|---:|---:| | 1,000 | 0.160 ms | 0.089 ms | 45.81% | 1.85x | 3/3 | 9.91% | | 20,000 | 27.895 ms | 2.929 ms | 89.43% | 9.46x | 3/3 | 7.85% | | 50,000 | 164.960 ms | 7.342 ms | 95.52% | 22.33x | 3/3 | 1.21% | | 100,000 | 665.564 ms | 15.840 ms | 97.62% | 42.02x | 3/3 | 2.23% | The small-graph effect is intentionally modest; this targets very broad HMR invalidations in large applications. ## Validation - targeted Prettier: pass - targeted ESLint: pass - `pnpm --filter @vercel/turbopack-ecmascript-runtime check:nodejs`: pass - `CARGO_TARGET_DIR=/home/vercel-sandbox/next.js/target cargo check -p turbopack-ecmascript-runtime`: pass - GPT-5.6 Sol xhigh + Claude Opus 4.8 xhigh autoreview: clean after addressing a first-round dependency-chain retention finding (0 findings, correctness 0.99) The aggregate runtime TypeScript check remains blocked by an existing `runtime-utils.ts:239` `EsmExport` type mismatch. The identical `check:browser-dev-client` failure reproduces on the untouched baseline and is unrelated to this file. --------- Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
Array.shift()calls in the HMR affected-module breadth-first traversal with a monotonically increasing queue index.Why
getAffectedModuleEffectscan enqueue a wide set of parents when a shared dependency changes. Repeatedly shifting the queue moves the remaining array contents on every iteration, making broad invalidations increasingly expensive. Indexed reads keep traversal FIFO and make queue consumption linear.The slot clearing is important for deep graphs: it avoids retaining every processed item's copied
dependencyChainuntil traversal returns.Benchmark
Three independent 8-vCPU/16-GiB Vercel Sandbox workers ran Node.js 24.14.1 from exact commit
0950e8ae05db20c33302f02257114f5b857edabc. The balancedA1/B1/B2/A2benchmark mirrors this loop for one changed shared dependency imported by N root modules, including dependency-chain allocation. Each phase used three warm-ups and nine samples.shift()medianThe small-graph effect is intentionally modest; this targets very broad HMR invalidations in large applications.
Validation
pnpm --filter @vercel/turbopack-ecmascript-runtime check:nodejs: passCARGO_TARGET_DIR=/home/vercel-sandbox/next.js/target cargo check -p turbopack-ecmascript-runtime: passThe aggregate runtime TypeScript check remains blocked by an existing
runtime-utils.ts:239EsmExporttype mismatch. The identicalcheck:browser-dev-clientfailure reproduces on the untouched baseline and is unrelated to this file.