Skip to content

refactor(minifier): Math.pow(a,b) -> a ** (+b) instead of (+a) ** (+b)#9154

Merged
Boshen merged 2 commits intomainfrom
02-16-refactor_minifier_math.pow_a_b_-_a_b_instead_of_a_b_
Feb 16, 2025
Merged

refactor(minifier): Math.pow(a,b) -> a ** (+b) instead of (+a) ** (+b)#9154
Boshen merged 2 commits intomainfrom
02-16-refactor_minifier_math.pow_a_b_-_a_b_instead_of_a_b_

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Feb 16, 2025

It's currently minifying twice through:

Math.pow(a, b) -> (+a) ** (+b) -> a ** (+b)

Correct me if this is wrong, i.e. we need to keep (+a) in the fold pass.

@Boshen Boshen requested a review from sapphi-red February 16, 2025 02:56
@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 16, 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-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Feb 16, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 16, 2025

CodSpeed Performance Report

Merging #9154 will not alter performance

Comparing 02-16-refactor_minifier_math.pow_a_b_-a_b_instead_of_a_b (b0f1c81) with main (9e3571f)

Summary

✅ 33 untouched benchmarks

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is safe. I didn't do it this way initially because it was a bit difficult to verify if it's safe.

Co-authored-by: 翠 / green <green@sapphi.red>
@Boshen Boshen merged commit 814eab6 into main Feb 16, 2025
26 checks passed
@Boshen Boshen deleted the 02-16-refactor_minifier_math.pow_a_b_-_a_b_instead_of_a_b_ branch February 16, 2025 04:11
@magic-akari
Copy link
Contributor

This will change the order of side effects.
For example, in the code below, before transformation, values are taken sequentially and then computed, so it outputs "effect 1" followed by "effect 2".
After transformation, however, the order of side effects will change.

Math.pow({
    valueOf() {
        console.log("effect 1");
        return 1;
    }
}, {
    valueOf() {
        console.log("effect 2");
        return 1;
    }
},)

https://playground.oxc.rs/#eNqNkMFugzAMhl8F+QQSQqPSLuze27Q9AJc0MzRTYiMnwCrEuy9pgR43XxI7v7//VxbQ0MC7Ctdq4DlfWspiTcqO+NHlRbYNUmkmzxYry33eAnYd6pDVLRRvT41gGIWyehutLa3lzvg/9PQ3tIASGJoFZKR0+BsF9QNNp6zHEqyhcDRe84DQBBlTc3MXtnsXRJHvWNwmXksYlHiUO5NH0Xg2Fkm5CICAPlTfPloPglE04acSJP9cTr735Xg/2A9aUNJjDAXoTy/1K0SF5i/sMeWPjTNkOvPQOkW9PSJrdslvtylhvpoYZVA6Snbn+JFB2J4tz4kwoVzYH+/r+gv+QaC4

@sapphi-red
Copy link
Member

sapphi-red commented Feb 18, 2025

@magic-akari Like other minifiers, OXC minifier assumes .valueOf to be sideeffect free, so that order change is fine.
https://github.com/oxc-project/oxc/tree/main/crates/oxc_minifier#:~:text=.toString()%2C,console.log(%27sideeffect%27)%20%7D%20%7D

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.

3 participants