Skip to content

feat(mangler)!: enable top_level by default for modules and commonjs#18278

Merged
graphite-app[bot] merged 1 commit intomainfrom
01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs
Feb 6, 2026
Merged

feat(mangler)!: enable top_level by default for modules and commonjs#18278
graphite-app[bot] merged 1 commit intomainfrom
01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Jan 20, 2026

I think we can enable top_level by default.

refs #18233

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Jan 20, 2026
Copy link
Member Author

sapphi-red commented Jan 20, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 20, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 47.46%

Comparing 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs (2bf7293) with main (ee2925b)

Summary

❌ 4 regressed benchmarks
✅ 43 untouched benchmarks
⏩ 3 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation mangler[RadixUIAdoptionSection.jsx_keep_names] 14.2 µs 21.1 µs -32.92%
Simulation mangler[RadixUIAdoptionSection.jsx] 8.5 µs 16.1 µs -47.46%
Simulation mangler[cal.com.tsx] 2.2 ms 3.6 ms -38.85%
Simulation mangler[binder.ts] 539 µs 646.5 µs -16.62%

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sapphi-red sapphi-red force-pushed the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch 2 times, most recently from 7b195b5 to 4d973d7 Compare January 20, 2026 05:32
@sapphi-red sapphi-red marked this pull request as ready for review January 20, 2026 05:40
Copilot AI review requested due to automatic review settings January 20, 2026 05:40
@sapphi-red
Copy link
Member Author

CodSpeed Performance Report

Merging this PR will degrade performance by 47.83%

Comparing 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs (7b195b5) with main (78ca6ee)1

This is probably because we now run Mangler::collect_exported_symbols(program).

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 enables top-level name mangling by default for ES modules and CommonJS files, making the minifier more aggressive by default while preserving backward compatibility through the Option type.

Changes:

  • Changed MangleOptions.top_level from bool to Option<bool> with smart defaults based on module kind
  • Updated documentation to reflect the new default behavior (true for modules and CommonJS, false otherwise)
  • Updated all tests, examples, and snapshots to account for the new default behavior

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_mangler/src/lib.rs Core implementation: changed top_level to Option<bool> and added logic to determine default based on module kind
napi/minify/src/options.rs Updated NAPI bindings to pass through the optional boolean without unwrapping
napi/minify/index.d.ts Updated TypeScript type definitions with new default documentation
napi/playground/src/lib.rs Wrapped boolean value in Some() for the optional type
napi/minify/test/terser.test.ts Updated test to explicitly disable top-level mangling to preserve original behavior
crates/oxc_minifier/tests/mangler/mod.rs Updated test utilities to use with_unambiguous(true) and Some(true) for explicit top-level mangling
crates/oxc_minifier/tests/mangler/snapshots/mangler.snap Updated snapshots showing imported names now being mangled with top-level enabled
crates/oxc_minifier/examples/mangler.rs Changed to use None to leverage the new default behavior
tasks/track_memory_allocations/allocs_minifier.snap Memory allocation changes from the new behavior (minor increases in allocations)

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

@Boshen
Copy link
Member

Boshen commented Jan 20, 2026

hmm gotta fix the perf regression somehow.

@sapphi-red sapphi-red force-pushed the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch from 4d973d7 to fc97159 Compare February 6, 2026 05:22
@sapphi-red sapphi-red marked this pull request as draft February 6, 2026 06:07
@sapphi-red sapphi-red changed the base branch from main to graphite-base/18278 February 6, 2026 06:35
@sapphi-red sapphi-red force-pushed the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch from fc97159 to e6fad00 Compare February 6, 2026 06:35
@sapphi-red sapphi-red changed the base branch from graphite-base/18278 to 02-06-perf_mangler_use_bitset_for_keep_names_symbols_set February 6, 2026 06:35
@sapphi-red sapphi-red marked this pull request as ready for review February 6, 2026 06:44
@sapphi-red sapphi-red force-pushed the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch from e6fad00 to b2e095e Compare February 6, 2026 06:45
@sapphi-red sapphi-red force-pushed the 02-06-perf_mangler_use_bitset_for_keep_names_symbols_set branch from f4f93d9 to c482806 Compare February 6, 2026 06:45
@sapphi-red
Copy link
Member Author

#19023 improves ~40%, but the remaining 60% probably requires #18476

@sapphi-red sapphi-red requested a review from Boshen February 6, 2026 07:04
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Feb 6, 2026
@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 6, 2026

Merge activity

  • Feb 6, 7:19 AM UTC: Boshen added this pull request to the Graphite merge queue.
  • Feb 6, 7:28 AM UTC: The Graphite merge queue couldn't merge this PR because it had merge conflicts.
  • Feb 6, 8:35 AM UTC: This pull request can not be added to the Graphite merge queue. Please try rebasing and resubmitting to merge when ready.
  • Feb 6, 8:35 AM UTC: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..
  • Feb 6, 12:48 PM UTC: sapphi-red added this pull request to the Graphite merge queue.
  • Feb 6, 12:55 PM UTC: Merged by the Graphite merge queue.

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 6, 2026
@graphite-app graphite-app bot changed the base branch from 02-06-perf_mangler_use_bitset_for_keep_names_symbols_set to graphite-base/18278 February 6, 2026 07:29
@sapphi-red sapphi-red force-pushed the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch from b2e095e to a685a05 Compare February 6, 2026 09:24
@sapphi-red sapphi-red changed the base branch from graphite-base/18278 to main February 6, 2026 09:24
@sapphi-red sapphi-red force-pushed the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch from a685a05 to ae98f06 Compare February 6, 2026 12:42
#18278)

I think we can enable `top_level` by default.

refs #18233
@graphite-app graphite-app bot force-pushed the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch from ae98f06 to 2bf7293 Compare February 6, 2026 12:48
@graphite-app graphite-app bot merged commit 2bf7293 into main Feb 6, 2026
30 checks passed
@graphite-app graphite-app bot deleted the 01-20-feat_mangler_enable_top_level_by_default_for_modules_and_commonjs branch February 6, 2026 12:55
camc314 added a commit that referenced this pull request Feb 10, 2026
### 💥 BREAKING CHANGES

- 2bf7293 mangler: [**BREAKING**] Enable `top_level` by default for
modules and commonjs (#18278) (sapphi-red)
- 48b0542 span: [**BREAKING**] SourceType::ts should set module to
unambigious (#18873) (Boshen)

### 🚀 Features

- 500d071 minifier: Local traverse ctx and generated minifier traverse
(#19106) (Boshen)
- 142a1be parser: Detect binary files with TS1490 error (#19047)
(Boshen)
- e316857 allocator/bitset: Add `Ones` iterator to `BitSet` (#19027)
(sapphi-red)
- 742ad3f minifier: Default `invalid_import_side_effects` to `false`
(#18916) (sapphi-red)
- 0eff6be parser: Error JSX-like type assertions and generics in
`.mts`/`.cts` (#18910) (Boshen)
- 18320c6 span: Store file extension in `SourceType` (#18893) (Boshen)

### 🐛 Bug Fixes

- a7514e4 isolated-declarations: Preserve const context in literal type
inference (#19178) (camc314)
- 312e756 isolated-declarations: Preserve readonly literal initializers
(#19177) (camc314)
- d0ca8d0 isolated-declarations: Skip parenthesis when inferring type
(#19176) (camc314)
- 110c300 oxc_ecmascript: `+[false]` and `+[true]` should evaluate to
`NaN` (#19174) (copilot-swe-agent)
- f32ea19 semantic: Report redeclaration error for import bindings
conflicting with value declarations (#19068) (Boshen)
- 3aeba7a semantic: Report redeclaration error for `function a() {} var
a` in module mode (#19041) (Boshen)
- 35e32c6 coverage: Match Babel's options.json inheritance for test
fixtures (#19002) (Boshen)
- 463d60d semantic: Skip TS2391 for standalone computed-name class
methods (#19025) (Boshen)
- 56c086b parser: Add modifier ordering validation (TS1029) (#19024)
(Boshen)
- 6067a49 linter/jsdoc: False positive in `check-tag-names` for `@` in
email addresses and npm scopes (#19021) (Boshen)
- b13bb70 semantic/jsdoc: Inline tags like `{@link}` break jsdoc parsing
(#19019) (Boshen)
- e3609e3 regular_expression: Preserve UnicodeEscape CharacterKind in
string literals (#18998) (Boshen)
- 57917ee parser: Parse decorators on rest parameters (#18938) (Boshen)
- 487601b napi: Disable mimalloc on Windows to fix worker_threads crash
(#18923) (Boshen)
- 1f6b193 parser: Validate TypeScript import type options (#18889)
(Boshen)
- 1663184 parser: Allow conditional types in function type parameters
(#18886) (Boshen)
- 5758046 parser: Error on property access after instantiation
expression (#18887) (Boshen)
- 5eb4a94 parser: Handle `<<` as two `<` tokens in type argument
contexts (#18885) (Boshen)

### ⚡ Performance

- ed8c054 oxc_str: Add precomputed hash to Ident for fast HashMap
lookups (#19143) (Boshen)
- d4a0867 transformer_plugins: Switch ReplaceGlobalDefines from Traverse
to VisitMut (#19146) (Boshen)
- 9eb16b3 syntax: Pack ASCII identifier tables into single bitflag table
(#19088) (Boshen)
- e7595d1 mangler: Use BitSet for exported symbols set (#19023)
(sapphi-red)
- 2537924 semantic: Optimize scope resolution with fast paths and
inlining (#19029) (Boshen)
- 69a8d85 mangler: Use BitSet for keep_names symbols set (#19028)
(sapphi-red)
- f78c525 parser: Try hybrid parsing for jsx children and closing
element/fragments (#18789) (camchenry)

Co-authored-by: camc314 <[email protected]>
owjs3901 pushed a commit to owjs3901/oxc that referenced this pull request Feb 11, 2026
### 💥 BREAKING CHANGES

- 2bf7293 mangler: [**BREAKING**] Enable `top_level` by default for
modules and commonjs (oxc-project#18278) (sapphi-red)
- 48b0542 span: [**BREAKING**] SourceType::ts should set module to
unambigious (oxc-project#18873) (Boshen)

### 🚀 Features

- 500d071 minifier: Local traverse ctx and generated minifier traverse
(oxc-project#19106) (Boshen)
- 142a1be parser: Detect binary files with TS1490 error (oxc-project#19047)
(Boshen)
- e316857 allocator/bitset: Add `Ones` iterator to `BitSet` (oxc-project#19027)
(sapphi-red)
- 742ad3f minifier: Default `invalid_import_side_effects` to `false`
(oxc-project#18916) (sapphi-red)
- 0eff6be parser: Error JSX-like type assertions and generics in
`.mts`/`.cts` (oxc-project#18910) (Boshen)
- 18320c6 span: Store file extension in `SourceType` (oxc-project#18893) (Boshen)

### 🐛 Bug Fixes

- a7514e4 isolated-declarations: Preserve const context in literal type
inference (oxc-project#19178) (camc314)
- 312e756 isolated-declarations: Preserve readonly literal initializers
(oxc-project#19177) (camc314)
- d0ca8d0 isolated-declarations: Skip parenthesis when inferring type
(oxc-project#19176) (camc314)
- 110c300 oxc_ecmascript: `+[false]` and `+[true]` should evaluate to
`NaN` (oxc-project#19174) (copilot-swe-agent)
- f32ea19 semantic: Report redeclaration error for import bindings
conflicting with value declarations (oxc-project#19068) (Boshen)
- 3aeba7a semantic: Report redeclaration error for `function a() {} var
a` in module mode (oxc-project#19041) (Boshen)
- 35e32c6 coverage: Match Babel's options.json inheritance for test
fixtures (oxc-project#19002) (Boshen)
- 463d60d semantic: Skip TS2391 for standalone computed-name class
methods (oxc-project#19025) (Boshen)
- 56c086b parser: Add modifier ordering validation (TS1029) (oxc-project#19024)
(Boshen)
- 6067a49 linter/jsdoc: False positive in `check-tag-names` for `@` in
email addresses and npm scopes (oxc-project#19021) (Boshen)
- b13bb70 semantic/jsdoc: Inline tags like `{@link}` break jsdoc parsing
(oxc-project#19019) (Boshen)
- e3609e3 regular_expression: Preserve UnicodeEscape CharacterKind in
string literals (oxc-project#18998) (Boshen)
- 57917ee parser: Parse decorators on rest parameters (oxc-project#18938) (Boshen)
- 487601b napi: Disable mimalloc on Windows to fix worker_threads crash
(oxc-project#18923) (Boshen)
- 1f6b193 parser: Validate TypeScript import type options (oxc-project#18889)
(Boshen)
- 1663184 parser: Allow conditional types in function type parameters
(oxc-project#18886) (Boshen)
- 5758046 parser: Error on property access after instantiation
expression (oxc-project#18887) (Boshen)
- 5eb4a94 parser: Handle `<<` as two `<` tokens in type argument
contexts (oxc-project#18885) (Boshen)

### ⚡ Performance

- ed8c054 oxc_str: Add precomputed hash to Ident for fast HashMap
lookups (oxc-project#19143) (Boshen)
- d4a0867 transformer_plugins: Switch ReplaceGlobalDefines from Traverse
to VisitMut (oxc-project#19146) (Boshen)
- 9eb16b3 syntax: Pack ASCII identifier tables into single bitflag table
(oxc-project#19088) (Boshen)
- e7595d1 mangler: Use BitSet for exported symbols set (oxc-project#19023)
(sapphi-red)
- 2537924 semantic: Optimize scope resolution with fast paths and
inlining (oxc-project#19029) (Boshen)
- 69a8d85 mangler: Use BitSet for keep_names symbols set (oxc-project#19028)
(sapphi-red)
- f78c525 parser: Try hybrid parsing for jsx children and closing
element/fragments (oxc-project#18789) (camchenry)

Co-authored-by: camc314 <[email protected]>
OskarLebuda pushed a commit to OskarLebuda/oxc that referenced this pull request Feb 17, 2026
OskarLebuda pushed a commit to OskarLebuda/oxc that referenced this pull request Feb 17, 2026
### 💥 BREAKING CHANGES

- 2bf7293 mangler: [**BREAKING**] Enable `top_level` by default for
modules and commonjs (oxc-project#18278) (sapphi-red)
- 48b0542 span: [**BREAKING**] SourceType::ts should set module to
unambigious (oxc-project#18873) (Boshen)

### 🚀 Features

- 500d071 minifier: Local traverse ctx and generated minifier traverse
(oxc-project#19106) (Boshen)
- 142a1be parser: Detect binary files with TS1490 error (oxc-project#19047)
(Boshen)
- e316857 allocator/bitset: Add `Ones` iterator to `BitSet` (oxc-project#19027)
(sapphi-red)
- 742ad3f minifier: Default `invalid_import_side_effects` to `false`
(oxc-project#18916) (sapphi-red)
- 0eff6be parser: Error JSX-like type assertions and generics in
`.mts`/`.cts` (oxc-project#18910) (Boshen)
- 18320c6 span: Store file extension in `SourceType` (oxc-project#18893) (Boshen)

### 🐛 Bug Fixes

- a7514e4 isolated-declarations: Preserve const context in literal type
inference (oxc-project#19178) (camc314)
- 312e756 isolated-declarations: Preserve readonly literal initializers
(oxc-project#19177) (camc314)
- d0ca8d0 isolated-declarations: Skip parenthesis when inferring type
(oxc-project#19176) (camc314)
- 110c300 oxc_ecmascript: `+[false]` and `+[true]` should evaluate to
`NaN` (oxc-project#19174) (copilot-swe-agent)
- f32ea19 semantic: Report redeclaration error for import bindings
conflicting with value declarations (oxc-project#19068) (Boshen)
- 3aeba7a semantic: Report redeclaration error for `function a() {} var
a` in module mode (oxc-project#19041) (Boshen)
- 35e32c6 coverage: Match Babel's options.json inheritance for test
fixtures (oxc-project#19002) (Boshen)
- 463d60d semantic: Skip TS2391 for standalone computed-name class
methods (oxc-project#19025) (Boshen)
- 56c086b parser: Add modifier ordering validation (TS1029) (oxc-project#19024)
(Boshen)
- 6067a49 linter/jsdoc: False positive in `check-tag-names` for `@` in
email addresses and npm scopes (oxc-project#19021) (Boshen)
- b13bb70 semantic/jsdoc: Inline tags like `{@link}` break jsdoc parsing
(oxc-project#19019) (Boshen)
- e3609e3 regular_expression: Preserve UnicodeEscape CharacterKind in
string literals (oxc-project#18998) (Boshen)
- 57917ee parser: Parse decorators on rest parameters (oxc-project#18938) (Boshen)
- 487601b napi: Disable mimalloc on Windows to fix worker_threads crash
(oxc-project#18923) (Boshen)
- 1f6b193 parser: Validate TypeScript import type options (oxc-project#18889)
(Boshen)
- 1663184 parser: Allow conditional types in function type parameters
(oxc-project#18886) (Boshen)
- 5758046 parser: Error on property access after instantiation
expression (oxc-project#18887) (Boshen)
- 5eb4a94 parser: Handle `<<` as two `<` tokens in type argument
contexts (oxc-project#18885) (Boshen)

### ⚡ Performance

- ed8c054 oxc_str: Add precomputed hash to Ident for fast HashMap
lookups (oxc-project#19143) (Boshen)
- d4a0867 transformer_plugins: Switch ReplaceGlobalDefines from Traverse
to VisitMut (oxc-project#19146) (Boshen)
- 9eb16b3 syntax: Pack ASCII identifier tables into single bitflag table
(oxc-project#19088) (Boshen)
- e7595d1 mangler: Use BitSet for exported symbols set (oxc-project#19023)
(sapphi-red)
- 2537924 semantic: Optimize scope resolution with fast paths and
inlining (oxc-project#19029) (Boshen)
- 69a8d85 mangler: Use BitSet for keep_names symbols set (oxc-project#19028)
(sapphi-red)
- f78c525 parser: Try hybrid parsing for jsx children and closing
element/fragments (oxc-project#18789) (camchenry)

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

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments