Optimize constant ESM import bindings - #98603
Draft
lukesandberg wants to merge 6 commits into
Draft
Conversation
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Contributor
Failing test suitesCommit: 981232b | About building and testing Next.js
Expand output● app-dir-hmr › filesystem changes › can navigate cleanly to a page that requires a change in the Webpack runtime Other failing CI jobs |
lukesandberg
commented
Sep 12, 2026
lukesandberg
commented
Sep 12, 2026
lukesandberg
commented
Sep 12, 2026
lukesandberg
commented
Sep 12, 2026
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
lukesandberg
commented
Sep 13, 2026
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
lukesandberg
commented
Sep 13, 2026
lukesandberg
commented
Sep 13, 2026
lukesandberg
commented
Sep 13, 2026
lukesandberg
commented
Sep 13, 2026
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Co-authored-by: Luke Sandberg <210140+lukesandberg@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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
Optimize Turbopack's generated code for named and default ESM imports whose bindings are known not to change after module evaluation. These imports are captured once in a generated local, while live bindings continue to read through the module namespace.
Why?
Turbopack currently preserves every imported binding as a namespace property access at each use. That is necessary for genuinely live bindings, but adds repeated property reads and generated code for the common case where an export is constant.
How?
The import code generator follows statically known re-export chains and reuses the existing export-liveness analysis. Capture eligibility is a cached Turbo Task keyed by module, export, and chunking context, so repeated uses share the re-export walk and circuit-breaker lookup. It emits a compact, deterministic local binding only when the resolved export is constant and evaluation order is safe. Besides removing repeated property reads, direct calls through these locals no longer need the
(0, namespace.property)(...)form used to avoid binding the namespace asthis. Circuit breakers, mutable or live exports, assignment targets, namespace imports, externals, and unknown export shapes retain the conservative namespace access.Snapshot and execution coverage verifies named and default imports, re-exports, mangled export keys, call semantics, live updates, and circular-import safety.
Verification
cargo nextest run -p turbopack-tests --no-fail-fast(412 passed)cargo check -p turbopack-ecmascriptcargo fmt --all -- --check