Skip to content

refactor(minifier): consolidate DeadCodeElimination into PeepholeOptimizations#18128

Merged
graphite-app[bot] merged 1 commit intomainfrom
refactor/minifier-dce-consolidation
Jan 17, 2026
Merged

refactor(minifier): consolidate DeadCodeElimination into PeepholeOptimizations#18128
graphite-app[bot] merged 1 commit intomainfrom
refactor/minifier-dce-consolidation

Conversation

@Boshen
Copy link
Copy Markdown
Member

@Boshen Boshen commented Jan 17, 2026

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

  • All 466 minifier tests pass
  • Conformance tests pass
  • Code formatted with just fmt

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 17, 2026 10:37
@github-actions github-actions Bot added A-minifier Area - Minifier C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Jan 17, 2026
Copy link
Copy Markdown
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 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: bool field to PeepholeOptimizations to control optimization mode
  • Added new_dce() constructor for creating DCE-only instances
  • Consolidated duplicate code from DeadCodeElimination into PeepholeOptimizations with conditional logic
  • Updated Compressor to use PeepholeOptimizations::new_dce() instead of separate DeadCodeElimination struct

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.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 17, 2026
Copy link
Copy Markdown
Member Author

Boshen commented Jan 17, 2026

Merge activity

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jan 17, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 6.82%

Comparing refactor/minifier-dce-consolidation (2d7ca96) with main (ba9c750)1

Summary

❌ 3 regressed benchmarks
✅ 35 untouched benchmarks
⏩ 7 skipped benchmarks2

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

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation minifier[cal.com.tsx] 35.5 ms 38.1 ms -6.82%
Simulation minifier[binder.ts] 4 ms 4.2 ms -3.38%
Simulation minifier[react.development.js] 2.5 ms 2.6 ms -3.41%

Footnotes

  1. No successful run was found on main (d8f5c66) during the generation of this report, so ba9c750 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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

…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)
@graphite-app graphite-app Bot force-pushed the refactor/minifier-dce-consolidation branch from 2d7ca96 to 6ec08e8 Compare January 17, 2026 10:45
@graphite-app graphite-app Bot merged commit 6ec08e8 into main Jan 17, 2026
21 checks passed
@graphite-app graphite-app Bot deleted the refactor/minifier-dce-consolidation branch January 17, 2026 10:51
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jan 17, 2026
graphite-app Bot pushed a commit that referenced this pull request Apr 27, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants