Skip to content

feat(minifier): mark more known global methods as side-effect free#13086

Merged
graphite-app[bot] merged 1 commit intomainfrom
08-14-feat_minifier_mark_more_global_methods_as_side-effect_free
Aug 16, 2025
Merged

feat(minifier): mark more known global methods as side-effect free#13086
graphite-app[bot] merged 1 commit intomainfrom
08-14-feat_minifier_mark_more_global_methods_as_side-effect_free

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Aug 14, 2025

closes #13067

Copilot AI review requested due to automatic review settings August 14, 2025 11:02
@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 14, 2025

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.

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Aug 14, 2025
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 extends the minifier's capability to mark more known global methods as side-effect free, allowing for better optimization. The changes update the side-effect analysis to recognize more pure global functions and static methods as safe to remove when their results are unused.

Key changes:

  • Added comprehensive lists of pure global functions and static methods
  • Updated test cases to reflect the new optimization behavior
  • Refined the side-effect detection logic for call and new expressions

Reviewed Changes

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

Show a summary per file
File Description
tasks/minsize/minsize.snap Updated benchmark results showing improved minification
crates/oxc_minifier/tests/peephole/obscure_edge_cases.rs Modified tests to expect optimization of Math.random(), Date.now(), and Object(null)
crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs Added comprehensive test coverage for pure global functions and methods
crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs Updated test to include assignment for RegExp optimization
crates/oxc_minifier/src/peephole/replace_known_methods.rs Updated tests to include assignments for proper test validation
crates/oxc_minifier/src/peephole/remove_unused_expression.rs Updated logic to use side-effect analysis for call expressions
crates/oxc_ecmascript/src/side_effects/may_have_side_effects.rs Core implementation adding pure function detection and extensive method coverage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 14, 2025

CodSpeed Instrumentation Performance Report

Merging #13086 will degrade performances by 3.36%

Comparing 08-14-feat_minifier_mark_more_global_methods_as_side-effect_free (fbe6663) with main (a36c3ce)

Summary

❌ 1 regressions
✅ 33 untouched benchmarks

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

Benchmarks breakdown

Benchmark BASE HEAD Change
minifier[cal.com.tsx] 30 ms 31 ms -3.36%

@Boshen Boshen force-pushed the 08-14-feat_minifier_mark_more_global_methods_as_side-effect_free branch from 7841316 to a1fa518 Compare August 14, 2025 11:36
@KTibow
Copy link

KTibow commented Aug 14, 2025

This doesn't quite close #13067 yet; for example, while this optimizes Math.random() it doesn't optimize Math.random (the mere access, likely left behind from something like const random = Math.random; const unused = () => random() * 2)

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Aug 16, 2025
Copy link
Member Author

Boshen commented Aug 16, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 08-14-feat_minifier_mark_more_global_methods_as_side-effect_free branch from e4215cc to fbe6663 Compare August 16, 2025 03:42
@graphite-app graphite-app bot merged commit fbe6663 into main Aug 16, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 08-14-feat_minifier_mark_more_global_methods_as_side-effect_free branch August 16, 2025 03:48
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 16, 2025
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