next.js
2002ec0e - Turbopack: only read the requested entries' assets in server HMR pulls (#102272)

Commit
1 day ago
Turbopack: only read the requested entries' assets in server HMR pulls (#102272) ### What? Server HMR pulls in Turbopack dev now read only the assets of the requested entries. Previously they read every server asset written in the session and filtered afterwards. ### Why? `Project::server_hmr_chunks_for_entries` called `VersionedContentMap::server_hmr_chunks_in_path`, which awaited `get_asset`, `content()` and `versioned_content()` for every path in the map, and only then filtered by entry path (`ServerHmrChunkLists::retain_entry_paths`). Every pull therefore depended on all written server assets, so any of them that had been invalidated got recomputed during the pull, even when the pull only needed one route. In the default configuration (per-route module graphs), the benchmark below shows little difference. The cost grows when route activation invalidates other routes' assets. For context, an earlier experiment combined the experimental single dev module graph prototype (#102098) with #102016 (before it landed) and a prototype of this change. Those were separate Turbopack trace sessions of 185 sequential `compile_route` calls. Over calls 166–185, the server HMR pulls took 73.4 s elapsed without the change and 1.5 s with it. That was a different base from this PR and wasn't re-measured here. ### How? - `server_hmr_chunks_in_path` takes the entry paths and filters by path *before* reading any asset. - `Project::server_hmr_chunks()` and `ServerHmrChunkLists::new` / `retain_entry_paths` are no longer used, so this PR removes them. - Enumerating the map's keys and depending on the whole `State` stay the same. That part is still linear in the number of written paths. It didn't stand out in the measurements, but I didn't profile it separately. ### Verification Native bindings built with `pnpm build-native-release-with-assertions`, on canary `d347e527`: - `test/development/app-dir/server-hmr/server-hmr.test.ts`: 21/21 - `test/development/app-dir/server-hmr-async-loader-variants`: 3/3 - `test/development/app-hmr`: `hmr` 6/6, `hmr-env` 4/4, `server-restart` 1/1 - `test/development/app-dir/hmr-deleted-page` 2/2, `hmr-move-file` 1/1, `hmr-parallel-routes` 1/1, `hmr-dynamic-component` 5/5 + 1/1, `server-components-hmr-cache` 17/17 - `cargo clippy -p next-api`: clean Benchmark: - **Setup:** `bench/nested-deps-app-router-many-pages`, 200 sequential MCP `compile_route` calls, persistent cache on, 10 s idle every 20 calls, release bindings. Default config (per-route graphs), 2 runs each. - **Result:** the sum of call latencies was 293 / 321 s on canary `d347e527` vs 279 / 285 s with this change. With only 2 runs each, I read that as roughly neutral in this configuration. - **Not run:** browser-based HMR benchmarks. <!-- NEXT_JS_LLM --> <!-- fleet eae44d1f-04d8-4982-9549-09273295df2b --> --------- Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Author
Parents
Loading