feat(dev): per-client ship map for HMR patch sizing#10208
Conversation
How to use the Graphite Merge QueueAdd the label graphite: merge-when-ready to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
4306577 to
824e009
Compare
824e009 to
b7dd607
Compare
cc1cfa2 to
9f4db0d
Compare
b1eafbf to
a0d4f5c
Compare
e5793fc to
49a06d5
Compare
49a06d5 to
a90f3de
Compare
a0d4f5c to
49572b5
Compare
a90f3de to
671f1e7
Compare
49572b5 to
3169c39
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3169c399fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Merging this PR will not alter performance
Comparing Footnotes
|
sapphi-red
left a comment
There was a problem hiding this comment.
(I only checked the behavior explanation comment in the test cases)
3169c39 to
fe5254d
Compare
671f1e7 to
079f19e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe5254dde5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
079f19e to
ab763dd
Compare
fe5254d to
80e1e7d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80e1e7d421
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ab763dd to
f9ee937
Compare
18e4ff3 to
e1d592c
Compare
8d37643 to
fad060c
Compare
e1d592c to
7194a94
Compare
Merge activity
|
7194a94 to
408e889
Compare
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
hyfdev
left a comment
There was a problem hiding this comment.
I found three important issues; details inline.
| let stable_id = normal_dep.stable_id.as_str(); | ||
| if shipped.get(stable_id).is_some_and(|stamp| !stamp_table.is_stale(stable_id, *stamp)) | ||
| { | ||
| continue; |
There was a problem hiding this comment.
Important: please keep traversing through current shipped modules. The Vite client does skip fetching a patch when the entire update is irrelevant to that tab, but a fetched patch can still co-carry an unexecuted importer from the server's static superset. I reproduced this with two tabs: a lazy module imports an executed shared module and another never-delivered dependency; editing the shared module makes the second tab fetch a patch that carries the lazy module but not that other dependency, so delivery records the lazy module as current. When that tab later loads the route, this continue skips the missing dependency and the parked factory throws MissingFactoryError from initModule. Please separate "visited" from "carried": omit the already-current module itself, but still walk through its static dependencies.
| modules: std::mem::take(&mut patch.carried), | ||
| }, | ||
| ) | ||
| .await; |
There was a problem hiding this comment.
Important: please drop updates whose client disconnected during computation. If a client disappears after the snapshot, the sequence-assignment loop leaves its patch at the placeholder seq = 0, but this unconditional insertion recreates a pending entry after remove_client already cleaned that session, and the invalid update is still exposed through on_hmr_updates. Vite ignores it because its socket lookup fails, so the pending entry can never be consumed; repeated races with fresh client IDs grow pending_payloads without a global bound. Retain only updates whose session was still present when the sequence was assigned.
| } | ||
| } | ||
|
|
||
| let update = self.render_hmr_patch(carried, changed_ids.clone(), stamp_table).await?; |
There was a problem hiding this comment.
Important: please bound the lifetime of these per-client patch artifacts. This loop now creates a distinct filename, and usually a sourcemap, for every client on every edit. The pinned Vite consumer stores them in BundledDev.memoryFiles, whose only cleanup is clear() when the server closes; importing a patch does not remove it. A long-running dev server therefore permanently retains roughly clients × edits complete patch artifacts. Please add delivery-time deletion plus bounded eviction for files never requested, or share one rendered artifact when clients have the same carried set.
hyfdev
left a comment
There was a problem hiding this comment.
Approved with the important follow-ups noted inline.
<!-- - What is this PR solving? Write a clear and concise description. - Reference the issues it solves (e.g. `fixes #123`). - What other alternatives have you explored? - Are there any parts you think require more attention from reviewers? Also, please make sure you do the following: - Read the Contributing Guidelines at https://rolldown.rs/contribution-guide/. - Check that there isn't already a PR that solves the problem the same way. If you find a duplicate, please help us review it. - Update the corresponding documentation if needed. - Include relevant tests that fail without this PR but pass with it. If the tests are not included, explain why. Thank you for contributing to Rolldown! --> ## Summary For full design and principles, please refer to #10164 (comment). This PR adds the server-side **ship map**: a per-client record of which factory versions each browser tab already has, so patches and lazy chunks carry only changed, not-yet-shipped factories. ## Example The stateful server's ship map would incrementally ship factories that are only outdated or never shipped. ### The module graph ```mermaid flowchart LR app["app.js"] --> foo["foo.js<br/>(import.meta.hot.accept — boundary)"] foo --> bar["bar.js"] bar --> baz["baz.js<br/>(edited twice)"] ``` ### Server & client interaction ```mermaid sequenceDiagram participant S as Server (keeps shipped[C]) participant C as Browser tab C Note over C: initial bundle is scope-hoisted — no factories registered on the client yet Note over S: shipped[C] = { } Note over S,C: ① first edit of baz.js S->>C: patch 1 — factories foo@v0 + bar@v0 + baz@v1 (whole re-run chain, nothing shipped yet) C->>C: re-run baz → bar → foo, foo accepts Note over S: shipped[C] = { foo@v0, bar@v0, baz@v1 } Note over S,C: ② second edit of baz.js S->>C: patch 2 — factory baz@v2 only (foo@v0 and bar@v0 are still current in shipped[C]) C->>C: re-run baz → bar → foo, foo accepts Note over S: shipped[C] = { foo@v0, bar@v0, baz@v2 } ``` The first edit ships the whole re-run chain because the initial bundle is scope-hoisted, so the client holds no factories yet. The second edit ships only `baz` — the ship map says `foo` and `bar` were already delivered and are not stale. Rendered, the flow reads: app.js ──> foo.js ──> bar.js ──> baz.js (accept) (edited) edit ① patch = [foo@v0, bar@v0, baz@v1] shipped[C]: {} -> {foo@v0, bar@v0, baz@v1} edit ② patch = [baz@v2] shipped[C]: baz v1 -> v2, rest untouched
408e889 to
80c3022
Compare
…es (#10223) <!-- - What is this PR solving? Write a clear and concise description. - Reference the issues it solves (e.g. `fixes #123`). - What other alternatives have you explored? - Are there any parts you think require more attention from reviewers? Also, please make sure you do the following: - Read the Contributing Guidelines at https://rolldown.rs/contribution-guide/. - Check that there isn't already a PR that solves the problem the same way. If you find a duplicate, please help us review it. - Update the corresponding documentation if needed. - Include relevant tests that fail without this PR but pass with it. If the tests are not included, explain why. Thank you for contributing to Rolldown! --> ## Summary For full design and principles, please refer to #10164 (comment). The dev server tracks which module factories it has shipped per client in #10208. But modules that the entry chunk evaluated at top level never in the ship map. A lazy compile that subtracts only the ship man therefor re-ships factories the client already holds, which causes a size bloat in lazy-compilation chunks. This PR introduces a second per-client record - the `top_level_evaluated` map. This map contains the statically evaluated modules so that these modules are not shipped as factories in lazy compilation chunks again when the factories are not changed and only their exports are needed.
…es (#10223) <!-- - What is this PR solving? Write a clear and concise description. - Reference the issues it solves (e.g. `fixes #123`). - What other alternatives have you explored? - Are there any parts you think require more attention from reviewers? Also, please make sure you do the following: - Read the Contributing Guidelines at https://rolldown.rs/contribution-guide/. - Check that there isn't already a PR that solves the problem the same way. If you find a duplicate, please help us review it. - Update the corresponding documentation if needed. - Include relevant tests that fail without this PR but pass with it. If the tests are not included, explain why. Thank you for contributing to Rolldown! --> ## Summary For full design and principles, please refer to #10164 (comment). The dev server tracks which module factories it has shipped per client in #10208. But modules that the entry chunk evaluated at top level never in the ship map. A lazy compile that subtracts only the ship man therefor re-ships factories the client already holds, which causes a size bloat in lazy-compilation chunks. This PR introduces a second per-client record - the `top_level_evaluated` map. This map contains the statically evaluated modules so that these modules are not shipped as factories in lazy compilation chunks again when the factories are not changed and only their exports are needed.
## [1.2.0] - 2026-07-15 ### 🚀 Features - dev: skip shipping factories for newly imported top-level modules (#10223) by @h-a-n-a - dev: per-client ship map for HMR patch sizing (#10208) by @h-a-n-a - dev: client-side HMR (#10164) by @h-a-n-a - dev: send a full-reload update to clients when a tsconfig changes (#10262) by @shulaoda - treat `import.meta['url']` and `import.meta['ROLLUP_FILE_URL_*']` as side-effect free (#10267) by @sapphi-red - rewrite `import.meta['url']` (#10251) by @sapphi-red - add `FILE_NOT_FOUND` error (#10220) by @sapphi-red - treat `import.meta.ROLLUP_FILE_URL_*` as side-effect free (#10217) by @sapphi-red ### 🐛 Bug Fixes - sourcemap: preserve unmapped boundaries during composition (#10254) by @hyfdev - `[format]` in `*FileNames` option for ESM format should be `es` instead of `esm` (#10214) by @sapphi-red - sourcemap: preserve coarse mappings during composition (#10249) by @hyfdev - rolldown_plugin_vite_import_glob: support tsconfig paths with `import.meta.glob` (#10167) by @sapphi-red - dev: clear tsconfig caches for bare full builds (#10276) by @shulaoda - dev: force a full rebuild when a tsconfig changes (#10261) by @shulaoda - treat rooted drive-less module ids as absolute in preserveModules naming (#10235) by @IWANABETHATGUY - watch: rebuild when tsconfig files change (#10258) by @shulaoda - watch: drop tsconfig-merged transform options on each rebuild (#10257) by @shulaoda - incorrect `EMPTY_IMPORT_META` warning for `import.meta.ROLLUP_FILE_URL_*` for CJS output (#10221) by @sapphi-red - deconflict: rename CJS locals shadowing wrapped-ESM namespace objects (#9970) by @IWANABETHATGUY - rolldown: drop the unused runtime module after entry-level external flattening (#10237) by @IWANABETHATGUY - rolldown: re-propagate has_dynamic_exports to transitive star importers (#10239) by @IWANABETHATGUY - tree-shaking: tree-shake destructured dynamic import namespace bindings (#10213) by @logaretm - s390x: use json-escape-simd 3.1.1 for big-endian JSON escaping fix (#10211) by @satyamg1620 ### 🚜 Refactor - dev: move full-reload to client side (#10207) by @h-a-n-a - readability follow-ups to the ReplaceWith migration (#10286) by @IWANABETHATGUY - replace take_in-then-write-back with ReplaceWith and by-value moves (#10285) by @Boshen - share the main resolver's cache with the transformer's tsconfig lookups (#10205) by @shulaoda - rolldown: extract the ns star-external __reExport emission rule into LinkingMetadata (#10238) by @IWANABETHATGUY - rolldown: unify link/generate diagnostics into a Diagnostics accumulator (#10234) by @IWANABETHATGUY - sourcemap_filenames: drop dead sourcemap-filename plumbing (#10189) by @IWANABETHATGUY - extract external import symbol merging into a method (#10224) by @IWANABETHATGUY - rolldown: skip CJS namespace merging under strict execution order (#10203) by @hyfdev - resolve the manual tsconfig per file instead of once at startup (#10200) by @shulaoda - rolldown: route interop ESM init emission through a shared init-target view (#10202) by @hyfdev - rolldown: collapse vestigial wrap-kind state and share chunk sort helper (#10201) by @hyfdev ### 📚 Documentation - show plugin kinds in JSDoc and each hook's description (#10218) by @sapphi-red - add an explanation about removing imports from external modules without any messages (#10215) by @sapphi-red ### ⚡ Performance - sourcemap: owned merge in SourceJoiner::join (4005->5 allocs/chunk) (#10250) by @Boshen - avoid redundant sourcemap string copies in collapse and minify paths (#10093) by @Boshen ### 🧪 Testing - code-splitting: establish strict-order review baselines (#10287) by @hyfdev - dev: add hot API test cases (#10181) by @h-a-n-a - code-splitting: normalize strict execution order variants (#10277) by @hyfdev - code-splitting: harden strict execution order coverage (#10252) by @hyfdev - code-splitting: add strict execution order regressions (#10253) by @hyfdev ### ⚙️ Miscellaneous Tasks - deps: update github actions (#10241) by @renovate[bot] - deps: update oxc to 0.140.0 (#10274) by @shulaoda - update Yunfei's GitHub username (#10275) by @hyfdev - deps: update napi (#10260) by @renovate[bot] - deps: update test262 submodule for tests (#10266) by @rolldown-guard[bot] - deps: update dependency vite-plus to v0.2.4 (#10256) by @renovate[bot] - deps: update napi (#10240) by @renovate[bot] - deps: update oxc resolver to v11.24.2 (#10245) by @renovate[bot] - deps: update rust crates (#10244) by @renovate[bot] - disable Renovate updates for idna_adapter (#10248) by @shulaoda - deps: update oxc resolver to v11.24.1 (#10232) by @renovate[bot] - deps: update rust crate oxc_sourcemap to v8.1.1 (#10233) by @renovate[bot] - deps: update dependency rolldown-plugin-dts to ^0.27.0 (#10206) by @renovate[bot] - deps: upgrade sugar_path to v3 (#10230) by @hyfdev - add `dist-*` to `.gitignore` in sourcemap-filenames/hash-final-content fixture (#10216) by @sapphi-red - deps: update dependency rust to v1.97.0 (#10209) by @renovate[bot] ### ❤️ New Contributors * @satyamg1620 made their first contribution in [#10211](#10211) Co-authored-by: shulaoda <[email protected]>

Summary
For full design and principles, please refer to #10164 (comment).
This PR adds the server-side ship map: a per-client record of which factory versions each browser tab already has, so patches and lazy chunks carry only changed, not-yet-shipped factories.
Example
The stateful server's ship map would incrementally ship factories that are only outdated or never shipped.
The module graph
flowchart LR app["app.js"] --> foo["foo.js<br/>(import.meta.hot.accept — boundary)"] foo --> bar["bar.js"] bar --> baz["baz.js<br/>(edited twice)"]Server & client interaction
sequenceDiagram participant S as Server (keeps shipped[C]) participant C as Browser tab C Note over C: initial bundle is scope-hoisted — no factories registered on the client yet Note over S: shipped[C] = { } Note over S,C: ① first edit of baz.js S->>C: patch 1 — factories foo@v0 + bar@v0 + baz@v1 (whole re-run chain, nothing shipped yet) C->>C: re-run baz → bar → foo, foo accepts Note over S: shipped[C] = { foo@v0, bar@v0, baz@v1 } Note over S,C: ② second edit of baz.js S->>C: patch 2 — factory baz@v2 only (foo@v0 and bar@v0 are still current in shipped[C]) C->>C: re-run baz → bar → foo, foo accepts Note over S: shipped[C] = { foo@v0, bar@v0, baz@v2 }The first edit ships the whole re-run chain because the initial bundle is scope-hoisted, so the client holds no factories yet. The second edit ships only
baz— the ship map saysfooandbarwere already delivered and are not stale.Rendered, the flow reads:
app.js ──> foo.js ──> bar.js ──> baz.js
(accept) (edited)
edit ① patch = [foo@v0, bar@v0, baz@v1] shipped[C]: {} -> {foo@v0, bar@v0, baz@v1}
edit ② patch = [baz@v2] shipped[C]: baz v1 -> v2, rest untouched