Skip to content

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Sep 27, 2025

fixes #13912

As long as we know the variable is not re-assigned, the value is same even if we reordered the expression.
By using that fact, we can compress

function wrapper() { var x = foo, y = bar; return [x, y] }

to

function wrapper() { return [foo, bar] }

.

Copy link
Member Author

sapphi-red commented Sep 27, 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Sep 27, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 27, 2025

CodSpeed Instrumentation Performance Report

Merging #14184 will degrade performances by 8.35%

Comparing 09-27-feat_minifier_inline_single-use_variable_past_read-only_variables (6123684) with main (e4e963b)1

Summary

❌ 1 regression
✅ 32 untouched
⏩ 4 skipped2

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

Benchmarks breakdown

Benchmark BASE HEAD Change
minifier[cal.com.tsx] 32.7 ms 35.7 ms -8.35%

Footnotes

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

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

@sapphi-red sapphi-red force-pushed the 09-27-feat_minifier_inline_single-use_variable_past_read-only_variables branch from 4f18d55 to ddc6456 Compare September 27, 2025 12:29
@sapphi-red sapphi-red force-pushed the 09-27-feat_minifier_inline_single-use_variable_past_read-only_variables branch 2 times, most recently from 50a938a to 9e5b0b9 Compare September 27, 2025 12:55
@sapphi-red sapphi-red marked this pull request as ready for review September 27, 2025 13:00
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 implements an optimization to inline single-use variables past read-only variables in the JavaScript minifier. The change allows variables to be inlined even when they appear after other read-only variables in the declaration order, as long as the variables being moved past are not mutated.

  • Adds logic to detect read-only variables that can be safely reordered during inlining
  • Includes comprehensive test cases covering various scenarios with read-only and mutable variables
  • Updates existing tests to fix compatibility issues with the new optimization

Reviewed Changes

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

Show a summary per file
File Description
tasks/track_memory_allocations/allocs_minifier.snap Updated memory allocation metrics showing improved efficiency
tasks/minsize/minsize.snap Updated file size metrics showing reduced minified output sizes
crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs Added comprehensive test cases for the new read-only variable inlining optimization
crates/oxc_minifier/tests/peephole/esbuild.rs Commented out failing tests and adjusted existing test case to maintain compatibility
crates/oxc_minifier/src/peephole/minimize_statements.rs Implemented core logic to check for read-only variables and allow inlining past them

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

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Oct 1, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 1, 2025

Merge activity

…14184)

fixes #13912

As long as we know the variable is not re-assigned, the value is same even if we reordered the expression.
By using that fact, we can compress
```js
function wrapper() { var x = foo, y = bar; return [x, y] }
```
to
```js
function wrapper() { return [foo, bar] }
```
.
@graphite-app graphite-app bot force-pushed the 09-27-feat_minifier_inline_single-use_variable_past_read-only_variables branch from 9e5b0b9 to 6123684 Compare October 1, 2025 05:12
@graphite-app graphite-app bot merged commit 6123684 into main Oct 1, 2025
25 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 1, 2025
@graphite-app graphite-app bot deleted the 09-27-feat_minifier_inline_single-use_variable_past_read-only_variables branch October 1, 2025 05:18
@Boshen Boshen mentioned this pull request Oct 6, 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: Inline variables where only used once

3 participants