Skip to content

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

Merged
kdy1 merged 5 commits intomainfrom
kdy1/10095
Feb 28, 2025
Merged

fix(es/minifier): Skip inlining if the referential identity of a function matters#10123
kdy1 merged 5 commits intomainfrom
kdy1/10095

Conversation

@kdy1
Copy link
Copy Markdown
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
@changeset-bot
Copy link
Copy Markdown

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
@kdy1 kdy1 deleted the kdy1/10095 branch February 28, 2025 01:55
@codspeed-hq
Copy link
Copy Markdown

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
@swc-project swc-project locked as resolved and limited conversation to collaborators Mar 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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