Skip to content

Comments

perf: remove unnecessary assignment for default export#8127

Merged
graphite-app[bot] merged 1 commit intomainfrom
01-30-feat_remove_unnecessary_assignment_for_default_export
Jan 30, 2026
Merged

perf: remove unnecessary assignment for default export#8127
graphite-app[bot] merged 1 commit intomainfrom
01-30-feat_remove_unnecessary_assignment_for_default_export

Conversation

@shulaoda
Copy link
Member

@shulaoda shulaoda commented Jan 29, 2026

closes #4013, partially revert of #5856, and fixed issue #5847.

Copy link
Member Author


How to use the Graphite Merge Queue

Add 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.

@shulaoda shulaoda marked this pull request as ready for review January 29, 2026 18:09
Copilot AI review requested due to automatic review settings January 29, 2026 18:09
@shulaoda shulaoda changed the title feat: remove unnecessary assignment for default export perf: remove unnecessary assignment for default export Jan 29, 2026
@netlify
Copy link

netlify bot commented Jan 29, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit aa1b5f4
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/697c3cea3e0f60000815fc45

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the code generation for default exports by eliminating unnecessary intermediate variable assignments when exporting an identifier that doesn't require a snapshot.

Changes:

  • Added logic in ast_scanner to detect when export default identifier can reuse the existing symbol directly
  • Added logic in module_finalizers to skip creating export statements when the identifier already points to the default export symbol
  • Updated test snapshots to reflect the optimized output (removing intermediate variable assignments)
  • Added one test to the ignored list for circular default exports (behavioral difference with Rollup)

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rolldown/src/ast_scanner/mod.rs Adds optimization logic to detect when default export identifiers can reuse existing symbols
crates/rolldown/src/module_finalizers/mod.rs Adds logic to skip creating export statements when identifier already is the default export symbol
packages/rollup-tests/src/ignored-tests.js Adds circular-default-exports test to ignored list with explanation
packages/rollup-tests/src/status.json Updates test counts (ignored +1, passed -1)
packages/rollup-tests/src/status.md Updates test counts in markdown format
Multiple test snapshot files Updates snapshots to reflect optimized output without intermediate variables
crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap Updates hashes due to code changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shulaoda shulaoda force-pushed the 01-30-feat_remove_unnecessary_assignment_for_default_export branch from 111645f to e828be0 Compare January 29, 2026 18:24
@shulaoda shulaoda marked this pull request as draft January 29, 2026 18:30
@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

Benchmarks Rust

  • target: main(8c05e14)
  • pr: 01-30-feat_remove_unnecessary_assignment_for_default_export(bd707f2)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     62.0±1.46ms        ? ?/sec    1.01     62.7±1.24ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.03     71.8±4.79ms        ? ?/sec    1.00     69.8±2.35ms        ? ?/sec
bundle/bundle@rome_ts                                        1.03     96.5±4.81ms        ? ?/sec    1.00     94.0±1.36ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    106.6±2.89ms        ? ?/sec    1.00    106.5±1.73ms        ? ?/sec
bundle/bundle@threejs                                        1.00     34.2±1.71ms        ? ?/sec    1.02     34.8±2.63ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.02     40.3±1.87ms        ? ?/sec    1.00     39.6±1.00ms        ? ?/sec
bundle/bundle@threejs10x                                     1.01   348.5±11.54ms        ? ?/sec    1.00    346.5±6.00ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    407.6±5.97ms        ? ?/sec    1.01    412.5±7.75ms        ? ?/sec
scan/scan@rome_ts                                            1.00     73.5±1.37ms        ? ?/sec    1.06     77.6±2.33ms        ? ?/sec
scan/scan@threejs                                            1.00     25.6±0.28ms        ? ?/sec    1.02     26.1±1.70ms        ? ?/sec
scan/scan@threejs10x                                         1.00    264.0±3.92ms        ? ?/sec    1.00    263.5±3.12ms        ? ?/sec

@shulaoda shulaoda force-pushed the 01-30-feat_remove_unnecessary_assignment_for_default_export branch from e828be0 to ac47766 Compare January 29, 2026 20:46
@shulaoda shulaoda linked an issue Jan 29, 2026 that may be closed by this pull request
@shulaoda shulaoda marked this pull request as ready for review January 29, 2026 20:49
Copilot AI review requested due to automatic review settings January 29, 2026 20:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sapphi-red
Copy link
Member

reopen issue #5847

Does this mean this PR will introduce a bug temporarily?

@shulaoda
Copy link
Member Author

shulaoda commented Jan 30, 2026

reopen issue #5847

Does this mean this PR will introduce a bug temporarily?

No, this has been fixed. I added the relevant test cases, but we no longer support the import .. from '..'; export default .. form. Imported symbols must be assigned to a local binding variable (See #8128 (comment)). I updated the description.

@shulaoda shulaoda force-pushed the 01-30-feat_remove_unnecessary_assignment_for_default_export branch from ac47766 to 07da754 Compare January 30, 2026 03:10
@sapphi-red
Copy link
Member

What do you mean by "no longer support"?

@shulaoda
Copy link
Member Author

What do you mean by "no longer support"?

Previously, #5856 supported the import a from '..'; export default a pattern without creating an intermediate local binding for a. However, this causes an issue: Rolldown’s tree-shaking and lazy barrel logic determine whether to load all import records based on whether a symbol is a local binding.

Rolldown distinguishes export default a by generating a local binding symbol, as discussed in #8128 (comment).

@shulaoda
Copy link
Member Author

shulaoda commented Jan 30, 2026

"no longer support"

So this means that creating an intermediate variable for import a from '..'; export default a is necessary. By "no longer support" I mean that I now understand the behavior correctly and believe this pattern should not be supported.

Supporting this pattern may be feasible, but it would likely require changes in the link stage. It might be a bit complex.

@sapphi-red
Copy link
Member

I see 👍

Copilot AI review requested due to automatic review settings January 30, 2026 04:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings January 30, 2026 04:43
@shulaoda shulaoda force-pushed the 01-30-feat_remove_unnecessary_assignment_for_default_export branch from 52d4154 to bd707f2 Compare January 30, 2026 04:44
@hyf0
Copy link
Member

hyf0 commented Jan 30, 2026

well done!

Copy link
Member Author

shulaoda commented Jan 30, 2026

Merge activity

  • Jan 30, 5:08 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jan 30, 5:08 AM UTC: shulaoda added this pull request to the Graphite merge queue.
  • Jan 30, 5:18 AM UTC: Merged by the Graphite merge queue.

@graphite-app graphite-app bot force-pushed the 01-30-feat_remove_unnecessary_assignment_for_default_export branch from bd707f2 to aa1b5f4 Compare January 30, 2026 05:08
@graphite-app graphite-app bot merged commit aa1b5f4 into main Jan 30, 2026
34 checks passed
@graphite-app graphite-app bot deleted the 01-30-feat_remove_unnecessary_assignment_for_default_export branch January 30, 2026 05:18
@github-actions github-actions bot mentioned this pull request Feb 4, 2026
shulaoda added a commit that referenced this pull request Feb 4, 2026
@github-actions github-actions bot mentioned this pull request Feb 4, 2026
shulaoda added a commit that referenced this pull request Feb 4, 2026
## [1.0.0-rc.3] - 2026-02-04

⚡ Remove Unnecessary Default Export Assignment

- Eliminates redundant variable assignments when exporting default values
- Reduces output bundle size and improves code clarity
```js
// index.js
var x = 42;
export default x;

// Before
var x = 42;
var entry_default = x;
export { entry_default as default };

// After
var x = 42;
export { x as default };
```

🐛 Avoid Unnecessary Facade Chunks

- Keep user-defined entry modules in their own chunks
- Reduces HTTP round trips and improves startup performance

```js
// main.js (entry module)
import { a } from './lib.js'
console.log(a)

// lib.js
export * from './counter.js'

// counter.js (entry module)
export const a = 100

// Before
dist/
├── main.js           → import { a } from './counter-chunk.js'; console.log(a)
├── counter.js        → export { a } from './counter-chunk.js' // ❌ facade chunk
└── counter-chunk.js  → export const a = 100

// After
dist/
├── main.js    → import { a } from './counter.js'; console.log(a)
└── counter.js → export const a = 100
```

### 🚀 Features

- expose `RUNTIME_MODULE_ID` constant for plugin authors (#8199) by @shulaoda
- warn unsupported combination of `preserveValueImports` and `importsNotUsedAsValues` in tsconfig.json (#8169) by @sapphi-red
- sophisticated watch tracking for load dependencies (#8092) by @sapphi-red
- add `inputMap` option to `minify` / `minifySync` functions (#8138) by @sapphi-red
- consolidate same tsconfig errors (#8119) by @sapphi-red
- include tsconfig file path in error messages (#8107) by @Copilot
- lazy-barrel: support incremental build mode (#8114) by @shulaoda

### 🐛 Bug Fixes

- rust: preserve dependencies added by `this.addWatchFile` (#8198) by @hyf0
- spawn `RuntimeModuleTask` after `build_start` to avoid race condition (#8182) by @shulaoda
- rust/dev: only close after the ongoing task finished (#8147) by @hyf0
- ensure `\0rolldown/runtime.js` will go through transform hook and add test (#8093) by @hyf0
- `[name]` in `assetFileNames` does not include the directory part (#8098) by @IWANABETHATGUY
- handle external module properties in namespace imports (#8124) by @IWANABETHATGUY
- keep user-defined entry modules in their own chunks (#8047) by @IWANABETHATGUY
- avoid `Unknown resolve error` error message (#8111) by @sapphi-red

### 💼 Other

- remove warnings  for building rolldown with `not(feature = "experimental")` (#8110) by @coolreader18

### 🚜 Refactor

- move `VERSION` to `constants` directory (#8200) by @shulaoda
- simplify import symbol check using `SymbolFlags` (#8193) by @shulaoda
- extract tsconfig option and transform options merging logic (#8168) by @sapphi-red
- filter empty module_groups before sorting (#8149) by @ShroXd
- lazy-barrel: use single `remove` instead of `contains_key` + `remove` (#8123) by @shulaoda
- lazy-barrel: avoid redundant call and inline `get_barrel_normal_module` (#8122) by @shulaoda
- use logger instead of console.log for warnings (#8117) by @IWANABETHATGUY
- module-loader: remove intermediate ModuleTaskOwnerRef type (#8113) by @shulaoda
- rename ReExportExternalModule to ReExportDynamicExports (#8104) by @IWANABETHATGUY

### 📚 Documentation

- add dynamic OG image generation (#8192) by @sapphi-red
- add dynamic OG image generation (#8191) by @sapphi-red
- add dynamic OG image generation (#8179) by @Copilot
- apis: add links to option descriptions in JSDoc comments (#8167) by @sapphi-red
- apis: clarify parameters of `resolveDynamicImport` hook (#8137) by @sapphi-red
- lazy-barrel: clarify default export behavior (#8128) by @shulaoda

### ⚡ Performance

- remove unnecessary assignment for default export (#8127) by @shulaoda

### 🧪 Testing

- dev: `this.addWatchFile` dependency should be preserved after reload (#8165) by @sapphi-red
- mark flaky `transform_runtime_module` test as ignored (#8178) by @Copilot
- rolldown_sourcemap: add test for coarse segments (#8166) by @sapphi-red
- dev: correctly assert file change (#8164) by @sapphi-red
- rust: `transform_runtime_module` test shouldn't panic inside (#8151) by @hyf0
- rust: fix flakiness of rust tests (#8150) by @hyf0
- mark `output.dynamicImportInCjs` tests as passed (#8125) by @shulaoda
- lazy-barrel: add test cases for default export (#8129) by @shulaoda
- rolldown_plugin_vite_manifest: use relative path for outPath (#8101) by @shulaoda

### ⚙️ Miscellaneous Tasks

- deps: update crate-ci/typos action to v1.43.1 (#8188) by @renovate[bot]
- deps: update rust crate ts-rs to v12 (#8160) by @renovate[bot]
- deps: update crate-ci/typos action to v1.43.0 (#8175) by @renovate[bot]
- deps: update rust crates (#8157) by @renovate[bot]
- deps: update oxc to v0.112.0 (#8171) by @renovate[bot]
- deps: update rollup submodule for tests to v4.57.1 (#8176) by @sapphi-red
- deps: update test262 submodule for tests (#8177) by @sapphi-red
- deps: update dependency oxlint to v1.43.0 (#8173) by @renovate[bot]
- deps: update dependency oxfmt to ^0.28.0 (#8170) by @renovate[bot]
- deps: update dependency rolldown-plugin-dts to v0.21.8 (#8163) by @renovate[bot]
- deps: update dependency vue-router to v5 (#8159) by @renovate[bot]
- deps: update github-actions (#8158) by @renovate[bot]
- deps: update npm packages (#8156) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.11.4 (#8140) by @renovate[bot]
- fix clippy replacement typo (#8136) by @IWANABETHATGUY
- disallow `HashMap::new` and `HashSet::new` by clippy (#8135) by @sapphi-red
- deps: update dependency rolldown-plugin-dts to v0.21.7 (#8126) by @renovate[bot]
- deps: update oxc resolver to v11.17.0 (#8121) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.11.3 (#8109) by @renovate[bot]

### ❤️ New Contributors

* @coolreader18 made their first contribution in [#8110](#8110)

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Compromise library not working in development anymore [Feature Request]: Remove unnecessary assign for default export

4 participants