refactor(minifier): consolidate DeadCodeElimination into PeepholeOptimizations#18128
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request successfully consolidates the DeadCodeElimination struct into PeepholeOptimizations by adding a dce boolean flag to differentiate between full peephole optimizations and DCE-only mode. The refactor removes approximately 140 lines of duplicated code while maintaining identical behavior.
Changes:
- Added
dce: boolfield toPeepholeOptimizationsto control optimization mode - Added
new_dce()constructor for creating DCE-only instances - Consolidated duplicate code from
DeadCodeEliminationintoPeepholeOptimizationswith conditional logic - Updated
Compressorto usePeepholeOptimizations::new_dce()instead of separateDeadCodeEliminationstruct
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_minifier/src/peephole/mod.rs | Removed DeadCodeElimination struct and consolidated its behavior into PeepholeOptimizations with conditional dce flag; added guards in various traverse methods to skip non-DCE optimizations when in DCE mode |
| crates/oxc_minifier/src/compressor.rs | Updated import to remove DeadCodeElimination and changed dead_code_elimination_with_scoping to use PeepholeOptimizations::new_dce() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
CodSpeed Performance ReportMerging this PR will degrade performance by 6.82%Comparing Summary
Performance Changes
Footnotes
|
…mizations (#18128) ## Summary - Remove duplicated `DeadCodeElimination` struct and consolidate into `PeepholeOptimizations` - Add internal `dce: bool` flag to differentiate between full peephole optimizations and DCE-only mode - Remove ~140 lines of duplicated code while maintaining identical behavior ## Test plan - [x] All 466 minifier tests pass - [x] Conformance tests pass - [x] Code formatted with `just fmt` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2d7ca96 to
6ec08e8
Compare
## Summary
In DCE mode, `enter_statement` was skipping `keep_track_of_pure_functions` via an `if ctx.state.dce { return; }` guard, so user-defined functions with empty or side-effect-free bodies were never recorded as pure. The two consumers of that map — `remove_unused_call_expr` (via `try_fold_expression_stmt`) and `remove_dead_code_call_expression` — **already run in DCE mode**, so the data was needed; only the producer was gated off.
The guard was introduced during the consolidation refactor in #18128, which preserved pre-consolidation behavior rather than being an intentional choice. Eliminating calls to side-effect-free functions is classic DCE, not a full-minify extra, so the tracker now runs in both modes.
```js
// before (minify: "dce-only" / rolldown treeshake: true)
function noop() {}
noop(); // kept
// after
// (empty)
```
## Test plan
- New test case `remove_pure_function_calls` covering the issue repro
- Two existing expectations in `dce_if_statement` / `dce_var_hoisting` updated where DCE now produces strictly smaller output (pure function + its only call both collapse)
- All 484 minifier unit tests pass
- `just minsize` shows no size-snapshot changes (DCE mode isn't exercised by minsize benchmarks)
Closes rolldown/rolldown#9211
Summary
DeadCodeEliminationstruct and consolidate intoPeepholeOptimizationsdce: boolflag to differentiate between full peephole optimizations and DCE-only modeTest plan
just fmt🤖 Generated with Claude Code