Repository navigation
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
This comment was marked as resolved.
This comment was marked as resolved.
1f0f0fb to
a4a360c
Compare
a4a360c to
478c1a8
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Merging this PR will improve performance by 3.09%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
…#10485) With strict execution order, a dynamically imported entry can still emit a one-purpose facade file even when every live import can initialize it directly. This PR removes those redundant files in both strict modes while preserving the value and initialization observed by the importing promise. ```js // before: the import loads a separate file whose only effect is activation await import("./page-b2.js"); // page-b2.js import { t as init_page_b } from "./page-b.js"; init_page_b(); // after: the import activates the implementation directly await import("./page-b.js").then((n) => (n.t(), n.n)); // page-b2.js is not emitted ``` ## Problem Each affected dynamic entry adds one emitted chunk and an extra module load without adding user code. On LobeHub wrap-all, #10456 still emits 1577 chunks, 59 more than the non-strict build; 58 of those are these activation-only facades. The extra file appears when strict execution order wraps a pure dynamic entry whose implementation still owns its entry chunk. It can happen in both wrap-all and on-demand modes; wrap-all reaches it more often because it wraps every eligible module. Strict lowering has two ways for such a facade to survive. The restore pass (which revives a facade removed by chunk optimization) already uses the call-site trigger policy from #10456. The creation pass, `create_order_wrap_entry_facades` (which splits an inline entry initializer into its own file), still decides from chunk loading alone and never asks whether every live `import()` can carry that initializer. The same output shape therefore keeps or removes a facade depending on which pass produced it. Collapsing the facade also means the implementation chunk must publish the namespace value that the facade used to return. That interface cannot be reconstructed from a stale retained-symbol set: aliases can widen it beyond the dynamic import's actual export usage, and a getter such as `x: () => x` can be rendered even when `x` is neither declared nor imported in the chunk. Reading or spreading that namespace then throws a `ReferenceError`. Non-strict builds are unaffected. Strict builds still retain a real facade for user or emitted entries, entries without a live `import()` call site, two-argument `import()`, TLA-tainted targets, host namespaces that may expose callable `then`, entries whose direct or transitive export-star chain reaches an external module, and facades already restored because another collapse proof failed. For the dynamic entries that do collapse, output-hook metadata changes with the file topology: the implementation is reported as a common chunk, so `isDynamicEntry` becomes `false`, `facadeModuleId` becomes `null`, and `exports` reports the common chunk's emitted linkage names instead of the facade's entry export list. Manifest and plugin consumers that key on entry metadata will therefore stop seeing a separate dynamic entry for exactly these removed facades; this is the same contract choice already made for optimizer-removed facades in #10456. ## Fix Use the same call-site proof when creating and restoring strict entry facades. When a pure dynamic entry has an initializer and every surviving `import()` can be rewritten safely, its implementation becomes a common chunk, each import points to that chunk and runs the initializer before resolving, and no separate facade is emitted. Removing the facade also removes the namespace object it would have exported. Strict lowering now records the exact export names selected by `DynamicImportExportsUsage` and materializes that narrowed interface in the implementation chunk. Its synthetic statement references every non-inlined binding behind those getters, allowing normal cross-chunk linking to keep, export, and import each getter target after the entry becomes a common chunk. Smart inline constants omit that reference only when the individual binding is actually safe to inline. If the namespace also has a real semantic consumer, that complete interface overrides the narrowing. This keeps the `ExportAll` runtime demand without turning a synthetic narrow namespace into an opaque user namespace read or initializing unrelated re-exports. Entry-level external stars are rendered on the facade chunk and keep that facade in every format. ESM would lose its chunk-level `export * from "external"` statement after reclassification. CJS-like formats would replace the facade's deduplicated `Object.keys` merge with one module-local `__reExport` per direct record; that differs for primitive module values and duplicate records, while a transitive external star is not available from the entry module's direct records at all. The provisional chunk's `entry_level_external_module_idx` covers both direct and transitive chains, so one format-independent guard preserves the complete interface and its existing merge behavior. This deliberately takes the same ordering tradeoff as #10456: the initializer runs in the rewritten import's promise continuation, one microtask after the host chunk settles, instead of during facade-module evaluation. The importing promise still resolves only after initialization, but a microtask queued during host evaluation can observe the target before it runs. Keeping the facade would preserve that timing but keep all 58 files; using different timing solely based on which lowering pass produced the facade would be inconsistent. Entries with no `import()` call site, including the remaining LobeHub HTML entry, are intentionally unchanged. LobeHub therefore moves from 1577 to 1519 chunks rather than to the 1518-chunk non-strict baseline. The analogous external-star loss in the pre-existing non-strict chunk optimizer is not changed here. It already reproduces on `main` without strict execution order and is being fixed independently in #10492, rather than adding another dependency to this stack. ## Validation - `retained_star_renamed_cycle` now spreads the emitted synthetic namespace at runtime and asserts its exact keys are `['_', 'common']`. This fails on the reviewed revision because the namespace contains a dangling `x` getter and an alias-widened `commonLeaf` getter. - New `retained_star_opaque_cycle` spreads the source-level dynamic namespace and asserts the complete interface. Its snapshots pin the cross-chunk import that backs `x`, so a genuine semantic namespace consumer cannot be accidentally narrowed. - New `retained_star_smart_constant_cycle` pins the smart inline-constant boundary in both strict modes: a getter's backing reference is omitted only when that exact constant can actually be inlined. - The direct and transitive ESM external-star fixtures are red without the guard because the resolved `import()` namespace loses `externalValue`. With the guard, each snapshot retains a facade carrying `export * from "external"`, and runtime assertions observe `x === 1`, `externalValue === 42`, and the expected initialization order. - New `cjs_dynamic_entry_external_star_keeps_facade` pins why direct CJS stars also keep the facade: a duplicated Proxy external is enumerated once, while a primitive external contributes its enumerable `0` and `1` keys. A collapsed module-local namespace would enumerate the Proxy twice and omit the primitive keys. - New `cjs_dynamic_entry_transitive_external_star` reproduces the reported `target -> barrel -> external` loss. It is red before the guard with `undefined !== 42`; the fixed snapshot retains the facade's chunk-level external merge and the runtime assertion observes `externalValue === 42`. - The related retained-star, fanout, namespace, and external-star fixtures pass, as do all 12 strict-order invariant tests. - LobeHub wrap-all emits 1518 `.js` files and one `.mjs`; all 1519 pass `node --check`. Expanding the external-star guard to every format does not change this ESM measurement, so all 58 chunk reductions remain. This measurement covers production output topology and syntax, not browser E2E behavior. - The output-hook metadata change is source-verified but is not pinned by a dedicated plugin or manifest fixture in this PR. - Targeted clippy for Rolldown, the all-features workspace check, Rust and repository formatting, filename lint, and `git diff --check` pass. Full-workspace clippy remains locally blocked by the pre-existing reasonless `#[ignore]` generated in the isolated-declaration test. Part of #10294.
|
Feel like too niche. |
When chunk optimization eliminates a dynamically imported entry facade, an ESM external star can disappear from the namespace returned by
import(). This reproduces onmainwithout strict execution order: local exports remain, but exports reached throughexport * from "external"becomeundefined.Problem
Rolldown delivers an entry's
export * from "external"toimport()callers through one of two shapes, chosen exclusively per record:export * from "external"statement, free at runtime. A generate-stage walk picks this shape by marking the recordEntryLevelExternal, which tells the namespace renderer to skip the runtime merge.import * as ns from "external"plus__reExport(entry_exports, ns)to copy the external's properties in at runtime.Facade elimination breaks the either/or assumption: the optimizer deletes the entry's file — the file-level statement has nowhere to live — and hands callers a namespace object synthesized in the implementation chunk, but the
EntryLevelExternalmark set for the file-level shape still suppresses the object-level merge. Neither shape is emitted; the external names silently vanish.Skipping eliminated facades during the walk would not be enough, because the mark lives on the shared import record and the
has_dynamic_exportsre-propagation behind it is transitive: a live entry reaching the same internal barrel legitimately marks the same record for its own file-level shape, and an unrelated invalidation seed can pull a simulated barrel into its importer closure — either way the recomputation treats the marked record as static and severs an upstream__reExportthe synthesized namespace still needs.There is a second, independent loss on the object-level path: the synthesized
import * as ns from "external"came from an AST factory that never emitted a with-clause, so an originalexport * from "external" with { ... }lost its import attributes.Fix
Teach the pipeline that a namespace standing in for an eliminated facade is an object-level consumer. When the optimizer replaces a dynamic facade with a namespace in its implementation chunk, it walks the internal
export *chain that carries dynamic exports and marks every participating module's namespace withSimulateFacadeChunk— "this namespace stands in for a deleted entry file".That reason drives both halves of the decision. On the renderer side, the shared emission predicate treats
SimulateFacadeChunklike a genuinely observed namespace, so the synthesized namespace regains its runtimeimport * as+__reExportmerge. On the propagation side, invalidation seed selection and recursivehas_dynamic_exportspropagation both use the newLinkingMetadata::entry_level_external_star_keeps_dynamic_exportshelper: anEntryLevelExternalrecord keeps counting as a dynamic source exactly when its owning module's namespace is genuinely observed (Unknown) or simulates an eliminated facade. The flag therefore always agrees with what the finalizer will emit, no matter how the importer closure grows — a live entry sharing the same barrel keeps its free file-levelexport *, while the eliminated facade's namespace keeps the runtime merge, both at once.The two predicates stay deliberately separate: the helper decides whether a namespace chain must remain dynamic (materialized and merged), while
ns_star_external_re_export_emittedstill decides how an already-materialized namespace merges the external in ESM versus CJS/IIFE/UMD. Ordinary entries continue to use their file-levelexport *without growing namespace proxy chains.The synthesized runtime namespace import now rebuilds the original record's import attributes, preserving
withversusassert, identifier versus string keys, and values.This is the pre-existing optimizer bug called out in #10485. It is based directly on
main, does not depend on #10485, and does not change facade-elimination eligibility or chunk topology.Validation
undefined !== 42and pass after it while preserving initialization order.live -> xcreates a normal invalidation seed,barrelimportsx, and the snapshot still contains both the barrel external merge and__reExport(target_exports, barrel_exports). Runtime assertions cover both live and eliminated-facade namespaces.export * from "external", while the eliminated dynamic facade emits runtimeimport *plus__reExport; both namespaces exposeexternalValue === 42.import * as ... from "external" with { type: "json" }after it.preserveModulesfixtures for issues Transitive export * statements not re-exported incjswithpreserveModules#7115 and [Bug] CJS Bundles redeclaring duplicate variable names #7233, including the chained case, retain their existing output without extra namespace proxies.rolldownlibrary tests, targetedrolldownclippy across all targets, Rust formatting, diff checks, and targeted spelling checks pass.