Repository navigation
Update the persistent scan cache design, and redesign module meta and moduleSideEffects - #16
Conversation
- Options hash: also hash `resolve` and `tsconfig`; skip callbacks into the host; from `experimental.cache`, hash only `assumeCacheableHooks`. - Key 1: add the watch mode (`this.meta.watchMode`). - Side effects: look for the tsconfig of every module whose id is an absolute path, also when the cache is off. - Saved resolve results: infer `module_def_format` as when the import was resolved. - When the cache is used: a lazy compilation reads the cache for modules that are not in memory yet. - Host inputs: a build dependency that changes while a bundler runs turns the cache off for that bundler until a restart.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7780b8bd9
ℹ️ 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".
…mplementation # Conflicts: # design-docs/0002-persistent-scan-cache.md
Move the rules for meta and moduleSideEffects from 0002 into 0003, and link to them from 0002, the Vite notes and the milestones. Add the terms module task, saved result, cached hook and creating resolution to the glossary.
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96128205ab
ℹ️ 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".
|
@codex review again |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2d8572b32
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1268e074eb
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ns (#11792) This PR makes Rolldown follow Rollup's rules for the `meta` and `moduleSideEffects` that plugins set on a module. The rules are in [`internal-docs/module-meta-and-side-effects/design.md`](https://github.com/rolldown/rolldown/blob/align-module-options-with-rollup/internal-docs/module-meta-and-side-effects/design.md), so please start the review there. The persistent scan cache in #11671 depends on them ([rolldown/cache 0003](rolldown/cache#16)). ## The rules 1. **Creation.** The first resolution of an id that reaches the module loader creates the module and sets its first `meta` (a top-level copy) and `moduleSideEffects`. Later resolutions, `this.resolve`, and `this.load` options for an existing module do not change it. 2. **Hook results.** Each object result of the module's own `load` and `transform` replaces `moduleSideEffects` when it is not `null` or `undefined`, and merges `meta` at the top level. 3. **Writes.** Any hook can change the values through `this.getModuleInfo(id)`. Writing `null` to `moduleSideEffects` clears it. Writes up to the end of `buildEnd` reach tree shaking. Rolldown ignores a `moduleSideEffects` write after `buildEnd`, so a later read and the next build do not see it, and warns about the first one in a build (`MODULE_SIDE_EFFECTS_WRITE_AFTER_BUILD_END`). 4. **Reading `moduleSideEffects`.** A read returns the decided value, or else a default value. The order of the defaults is in the design doc. From the time the module is created, a read never returns `null`. 5. **Lifetime.** A full build starts every module fresh. A partial scan (HMR, incremental rebuild, lazy compile) starts each changed module again from the resolution that created it. ``` a.js: resolveId('./x.css') → meta { from: 'a.js' } first → creates x.css b.js: resolveId('./x.css') → meta { from: 'b.js' } x.css exists → not used (before: merged) ``` ## What changes for plugins | Case | Before | After | | --- | --- | --- | | A second importer resolves the same id | Merged into the module | Ignored | | `this.resolve` | Changed the target module and returned its live `meta` | Returns only its own resolution: its `meta`, and its hook value or the default `moduleSideEffects` | | `this.load` options for an existing module | Merged | Ignored | | `meta` that a hook returns | Kept as the plugin's object | Kept as a top-level copy | | `getModuleInfo(id).moduleSideEffects` before the module is parsed, or after a write of `null` | `null` | The default value | | A write in `buildEnd`, or to an external | Changed only JS, or skipped | Reaches tree shaking | | A `moduleSideEffects` write after `buildEnd` | No warning | Ignored, with one warning per build | | HMR and incremental rebuild | A changed module could lose its values | Starts again from its creating resolution | | Lazy compilation | A lazy virtual module could get an empty chunk | Resolves the original import again | `moduleSideEffects` now lives only in Rust. `deferSyncScanData` and `invalidate` are removed. The default values for an external module and for `treeshake: false` come from #11422, which is on main. ## Differences from Rollup - The importer whose module task ends first creates the module (Rollup: the resolution that ends first). - When the option and `package.json` both give a value, the option wins. In Rollup, `@rollup/plugin-node-resolve` returns the `package.json` value as a hook value, so it wins. - An external Node.js built-in, such as `node:fs`, reads `false` (Rollup: `true`). - A read can return the `package.json` `sideEffects` value. - Writing `null` clears the value (Rollup stores `null` and treats it as `false`). - Writes after `buildEnd` are ignored, and Rolldown warns about the first one. In Rollup, a later read shows the written value. ## Impact - Vite needs vitejs/vite#24135 in the same release or before. Without it, the entry script of `<script type="module" src>` can be dropped when another importer creates it first. This can already happen today, and happens more often with this PR. - `@vitejs/plugin-vue` 6.0.10, `@vitejs/plugin-react` 6.0.2 and several Vite playgrounds give the same output. ## Performance Release builds, 10 runs each, M4 Pro (noise about 2%). The output was byte-identical. | Build | Change | | --- | --- | | Plain builds of 6 benchmark apps | None | | Vite with `@vitejs/plugin-react`, 5,000 modules | None | | Stress case, 10,000 modules | 3–5% slower (+45–55 ms of 1.1 s) | The stress case is not a usual build. Every relative import is resolved by a JS `resolveId` that returns `meta`, and `moduleSideEffects` of every module is read in `moduleParsed`, `renderChunk` and a `codeSplitting.groups` `name` function. The cost comes from: 1. One call into JS per module that a JS `resolveId` creates, so JS can set the first `meta` (`TaskContext::create_js_module_options`): about 2 µs per module. 2. A call into Rust per read of `moduleSideEffects` in the chunking context: about 0.6 µs per read. Possible fixes, not in this PR, are listed in `internal-docs/cache/implementation.md`. ## Where to look - JS: `createModuleOptions`, `saveResolutionOptions`, `resetModuleOptions` in `packages/rolldown/src/plugin/plugin-context-data.ts`. - Rust: `crates/rolldown_common/src/types/module_side_effects_overrides.rs`, `declared_side_effects_without_hook` in `crates/rolldown/src/ecmascript/ecma_module_view_factory.rs`, `try_spawn_new_task` in `crates/rolldown/src/module_loader/module_loader.rs`. - Machinery: the JS side cache section of `internal-docs/cache/implementation.md`. ## Tests New fixtures under `packages/rolldown/tests/fixtures/plugin/{context,resolve-id,transform}`. Rollup's `empty-module-no-treeshake` and `module-side-effects@resolve-id-external` tests now pass. ## Known gaps - The synchronous Rust chunking getter cannot call a JS `treeshake.moduleSideEffects` function. - A JS `treeshake.moduleSideEffects` function can run two times for one module; the first result is kept. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: andrew <[email protected]> Co-authored-by: 翠 <[email protected]>
metaandmoduleSideEffects. It builds on the rules without the cache in Rolldown'sinternal-docs/module-meta-and-side-effects/design.md(fix: follow Rollup for module meta and moduleSideEffects set by plugins rolldown#11792).metaandmoduleSideEffectsmoved to 0003.AI disclosure: These documents and this description were written with Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code