Skip to content

feat(ecmascript): add known-globals to side-effect-free property reads#20212

Merged
graphite-app[bot] merged 1 commit intomainfrom
fix/known-globals-side-effects
Mar 12, 2026
Merged

feat(ecmascript): add known-globals to side-effect-free property reads#20212
graphite-app[bot] merged 1 commit intomainfrom
fix/known-globals-side-effects

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Mar 11, 2026

Summary

close: #13067

Part of #19673

Depends on #20217.

Port known-globals lists from Rolldown to Oxc's side-effect detection:

  • Global identifiers (Math, Array, console, DOM classes, etc.) are now considered side-effect-free to access via is_known_global_identifier, matching Rolldown's GLOBAL_IDENT set
  • Property reads like Math.PI, console.log, Object.keys are considered side-effect-free via is_known_global_property
  • 3-level chains like Object.prototype.hasOwnProperty are supported via is_known_global_property_deep

Test plan

  • Added tests for known global identifiers (Math, Array, Object, console, etc.)
  • Added tests for known global property reads (Math.PI, Object.keys, etc.)
  • Added tests for 3-level chains (Object.prototype.hasOwnProperty, etc.)
  • Existing minifier test expectations updated for improved side-effect detection
  • All existing tests pass

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 11, 2026 03:01
@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Mar 11, 2026
@Dunqing Dunqing force-pushed the fix/known-globals-side-effects branch from 638deef to f0db348 Compare March 11, 2026 03:06
Copy link
Member Author

Dunqing commented Mar 11, 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 changes, fast-track this PR to the front of 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.

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

Ports Rolldown-style “known globals” knowledge into Oxc’s side-effect detection so the minifier/DCE can treat certain global identifier accesses and global property reads as side-effect-free, enabling more aggressive reductions and updating tests accordingly.

Changes:

  • Mark accesses to a large set of known global identifiers as side-effect-free (and add support for known global property reads + select 3-level chains).
  • Add property_write_side_effects() to the side-effects context and implement MayHaveSideEffects for AssignmentExpression / UpdateExpression.
  • Update and extend minifier test expectations to reflect improved side-effect detection.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/oxc_ecmascript/src/side_effects/expressions.rs Adds known-global identifier/property handling and new assignment/update side-effect logic.
crates/oxc_ecmascript/src/side_effects/context.rs Introduces property_write_side_effects() hook on the side-effects context.
crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs Adds tests for known globals/property reads/deep chains and updates expectations.
crates/oxc_minifier/tests/peephole/substitute_alternate_syntax.rs Updates expected outputs enabled by improved purity detection.
crates/oxc_minifier/tests/peephole/oxc.rs Updates integration expectation based on new optimizations.
crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs Updates keep-names related expectations for inlining behavior.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 11, 2026

Merging this PR will degrade performance by 6.3%

❌ 1 regressed benchmark
✅ 52 untouched benchmarks
⏩ 3 skipped benchmarks1

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

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation minifier[react.development.js] 2.6 ms 2.8 ms -6.3%

Comparing fix/known-globals-side-effects (4d3b18e) with feat/property-write-side-effects (cb8b1f6)

Open in CodSpeed

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.

@Dunqing Dunqing force-pushed the fix/known-globals-side-effects branch 3 times, most recently from 1f9ac5c to 3089aca Compare March 11, 2026 04:40
@Dunqing Dunqing changed the base branch from main to graphite-base/20212 March 11, 2026 04:42
@Dunqing Dunqing force-pushed the fix/known-globals-side-effects branch from 3089aca to cacff2f Compare March 11, 2026 04:42
@Dunqing Dunqing changed the base branch from graphite-base/20212 to feat/property-write-side-effects March 11, 2026 04:42
@Dunqing Dunqing requested review from Boshen and sapphi-red March 12, 2026 05:36
@Dunqing Dunqing force-pushed the feat/property-write-side-effects branch from 8172e82 to 7857402 Compare March 12, 2026 05:57
@Dunqing Dunqing force-pushed the fix/known-globals-side-effects branch 2 times, most recently from 4c397f0 to 4d3b18e Compare March 12, 2026 06:57
@Dunqing Dunqing force-pushed the feat/property-write-side-effects branch from 7857402 to cb8b1f6 Compare March 12, 2026 06:58
@graphite-app graphite-app bot changed the base branch from feat/property-write-side-effects to graphite-base/20212 March 12, 2026 07:25
@Dunqing Dunqing force-pushed the fix/known-globals-side-effects branch from 4d3b18e to 4d6a096 Compare March 12, 2026 07:33
@Dunqing Dunqing force-pushed the graphite-base/20212 branch from cb8b1f6 to 139ab68 Compare March 12, 2026 07:33
@Dunqing Dunqing changed the base branch from graphite-base/20212 to feat/property-write-side-effects March 12, 2026 07:33
Base automatically changed from feat/property-write-side-effects to main March 12, 2026 07:36
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 12, 2026
@Dunqing Dunqing force-pushed the fix/known-globals-side-effects branch from 4d6a096 to d12655d Compare March 12, 2026 09:05
@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 12, 2026

Merge activity

#20212)

## Summary

close: #13067

Part of #19673

Depends on #20217.

Port known-globals lists from Rolldown to Oxc's side-effect detection:

- **Global identifiers** (Math, Array, console, DOM classes, etc.) are now considered side-effect-free to access via `is_known_global_identifier`, matching Rolldown's `GLOBAL_IDENT` set
- **Property reads** like `Math.PI`, `console.log`, `Object.keys` are considered side-effect-free via `is_known_global_property`
- **3-level chains** like `Object.prototype.hasOwnProperty` are supported via `is_known_global_property_deep`

## Test plan

- [x] Added tests for known global identifiers (Math, Array, Object, console, etc.)
- [x] Added tests for known global property reads (Math.PI, Object.keys, etc.)
- [x] Added tests for 3-level chains (Object.prototype.hasOwnProperty, etc.)
- [x] Existing minifier test expectations updated for improved side-effect detection
- [x] All existing tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the fix/known-globals-side-effects branch from c4c894c to e7163b6 Compare March 12, 2026 09:23
@graphite-app graphite-app bot merged commit e7163b6 into main Mar 12, 2026
21 checks passed
@graphite-app graphite-app bot deleted the fix/known-globals-side-effects branch March 12, 2026 09:34
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 12, 2026
Boshen added a commit that referenced this pull request Mar 14, 2026
### 🚀 Features

- e7163b6 ecmascript: Add known-globals to side-effect-free property
reads (#20212) (Dunqing)
- 139ab68 ecmascript: Add `property_write_side_effects` to
`MayHaveSideEffectsContext` (#20217) (Dunqing)

### 🐛 Bug Fixes

- 78c264a parser: Fix conditional expressions with arrow-function
alternates in TS (#20356) (camc314)
- 5c97b14 minifier: Recognize object spread of object literals as
side-effect-free (#20299) (Boshen)
- 1ff5c1d transformer/typescript: Rewrite extensions in dynamic
`import()` expressions (#20121) (Sverre Johansen)
- 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent
panic (#20295) (Boshen)
- ade14d4 ecmascript: Enhance side-effect detection for classes,
TypedArrays, computed members, and spread (#20213) (Dunqing)

### ⚡ Performance

- 5474d0a semantic: V8-style walk-up reference resolution (#20292)
(Boshen)

### 📚 Documentation

- e4aa5b5 parser/napi, linter/plugins: Add JSDoc comments to raw
transfer constants (#20286) (overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
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.

minifier: maintain a model of globals

3 participants