Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/minifier): Skip inlining if the referential identity of a function matters #10123

Merged
merged 5 commits into from
Feb 28, 2025

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Feb 28, 2025

Description:

function a() {
    if (a.isInit) return;
    a.isInit = true;

    console.log('run')
}

function b() {
    a();

    console.log('after');
}

b();
b();

was minified as

function b() {
    (function a() {
        if (a.isInit) return;
        a.isInit = true, console.log('run');
    })(), console.log('after');
}
b(), b();

Which is wrong because the referential identity of a is important.

Related issue:

@kdy1 kdy1 added this to the Planned milestone Feb 28, 2025
@kdy1 kdy1 self-assigned this Feb 28, 2025
Copy link

changeset-bot bot commented Feb 28, 2025

🦋 Changeset detected

Latest commit: 5c5fc74

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kdy1 kdy1 changed the title fix(es/minifier): Skip inlining if a function has recursive access fix(es/minifier): Skip inlining if the referential identity of a function matters Feb 28, 2025
@kdy1 kdy1 marked this pull request as ready for review February 28, 2025 01:34
@kdy1 kdy1 requested review from a team as code owners February 28, 2025 01:34
@kdy1 kdy1 enabled auto-merge (squash) February 28, 2025 01:35
@kdy1 kdy1 disabled auto-merge February 28, 2025 01:55
@kdy1 kdy1 merged commit c08fe8d into main Feb 28, 2025
169 checks passed
@kdy1 kdy1 deleted the kdy1/10095 branch February 28, 2025 01:55
Copy link

codspeed-hq bot commented Feb 28, 2025

CodSpeed Performance Report

Merging #10123 will degrade performances by 3.24%

Comparing kdy1/10095 (7e4d5bd) with main (2304cd8)

Summary

❌ 2 regressions
✅ 189 untouched benchmarks

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

Benchmarks breakdown

Benchmark BASE HEAD Change
es/full/minify/libraries/moment 103.8 ms 107.2 ms -3.24%
es/minifier/libs/lodash 148.9 ms 153.7 ms -3.16%

@kdy1 kdy1 modified the milestones: Planned, v1.11.5 Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

The inside side-effect function will be wrongly improved on compress
1 participant