Skip to content

fix(side-effects): respect DefinePlugin purity evaluation#13628

Merged
ahabhgk merged 2 commits intomainfrom
fix-define-env-side-effects
Apr 7, 2026
Merged

fix(side-effects): respect DefinePlugin purity evaluation#13628
ahabhgk merged 2 commits intomainfrom
fix-define-env-side-effects

Conversation

@ahabhgk
Copy link
Copy Markdown
Contributor

@ahabhgk ahabhgk commented Apr 7, 2026

Summary

Respect DefinePlugin purity evaluation for side effects plugin

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings April 7, 2026 07:32
@ahabhgk ahabhgk force-pushed the fix-define-env-side-effects branch from 801e940 to e11536d Compare April 7, 2026 07:34
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

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test and updates the JS side-effects parser logic so expressions deemed pure by DefinePlugin (via evaluation) are respected during side-effect analysis, improving tree-shaking behavior.

Changes:

  • Add a new config case under side-effects/define-plugin to validate pruning of side-effect-free reexport chains under DefinePlugin.
  • Update _is_pure_expression to consult evaluate_expression(...).could_have_side_effects() before falling back to may_have_side_effects.
  • Introduce fixtures (lib/*, reexport.js) that exercise purity evaluation and package "sideEffects": false.

Reviewed changes

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

Show a summary per file
File Description
tests/rspack-test/configCases/side-effects/define-plugin/rspack.config.js Adds a dedicated config enabling sideEffects optimization + DefinePlugin to set NODE_ENV.
tests/rspack-test/configCases/side-effects/define-plugin/reexport.js Adds a reexport + conditionally-dead side effect to test purity evaluation.
tests/rspack-test/configCases/side-effects/define-plugin/lib/package.json Marks the fixture package as side-effect-free ("sideEffects": false).
tests/rspack-test/configCases/side-effects/define-plugin/lib/module.js Adds a simple exported symbol used by the test.
tests/rspack-test/configCases/side-effects/define-plugin/lib/index.js Reexports module.js and exports an additional unused symbol.
tests/rspack-test/configCases/side-effects/define-plugin/index.js Adds an assertion that certain modules are not present in the output bundle.
crates/rspack_plugin_javascript/src/parser_plugin/side_effects_parser_plugin.rs Changes purity detection to respect plugin-driven could_have_side_effects evaluation overrides.

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

Comment thread crates/rspack_plugin_javascript/src/parser_plugin/side_effects_parser_plugin.rs Outdated
Comment thread tests/rspack-test/configCases/side-effects/define-plugin/index.js
@ahabhgk
Copy link
Copy Markdown
Contributor Author

ahabhgk commented Apr 7, 2026

@codex review

@github-actions github-actions Bot added the release: bug fix release: bug related release(mr only) label Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

Rsdoctor Bundle Diff Analysis

Found 6 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
popular-libs 1.7 MB -41.0 B (-0.0%)
react-10k 5.7 MB 0
react-1k 826.9 KB 0
react-5k 2.7 MB 0
rome 984.1 KB 0
ui-components 5.0 MB 0
📋 Detailed Reports (Click to expand)

📁 popular-libs

Path: ../build-tools-performance/cases/popular-libs/dist/rsdoctor-data.json

📌 Baseline Commit: c8abe3cc83 | PR: #13608

Metric Current Baseline Change
📊 Total Size 1.7 MB 1.7 MB -41.0 B (-0.0%)
📄 JavaScript 1.7 MB 1.7 MB -41.0 B (-0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: popular-libs Bundle Diff

Generated by Rsdoctor GitHub Action

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 7, 2026

Merging this PR will degrade performance by 37.57%

🎉 Hooray! codspeed-node just leveled up to 5.2.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

❌ 2 regressed benchmarks
✅ 7 untouched benchmarks
⏩ 28 skipped benchmarks1

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

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation js@Traverse module graph by dependencies 530.2 µs 849.2 µs -37.57%
Simulation js@collect imported identifiers 210 µs 212.6 µs -1.25%

Comparing fix-define-env-side-effects (0070cda) with main (c8abe3c)

Open in CodSpeed

Footnotes

  1. 28 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

📦 Binary Size-limit

Comparing 0070cda to refactor: improve persistent cache load error handling (#13608) by jinrui

🎉 Size decreased by 4.34KB from 49.34MB to 49.34MB (⬇️0.01%)

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ahabhgk ahabhgk enabled auto-merge (squash) April 7, 2026 07:52
@ahabhgk ahabhgk merged commit c6bca7a into main Apr 7, 2026
37 checks passed
@ahabhgk ahabhgk deleted the fix-define-env-side-effects branch April 7, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants