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): Check type of assignment target before merging assignments #9617

Merged
merged 12 commits into from
Oct 14, 2024

Conversation

CPunisher
Copy link
Member

@CPunisher CPunisher commented Oct 4, 2024

Description:

Collect types of vars, maybe other optimization could benefit from this: merged_var_type: Option<Value<Type>>

When the variable is reassigned, the we merge the types with some simple rules:
None + None = None
None + Some(ty) = Some(ty)
Some(ty1) + Some(ty2) if ty1 == ty2 = Some(ty1)
Otherwise = Unknown

Related issue (if exists):
closes #8718

@CPunisher CPunisher requested a review from a team as a code owner October 4, 2024 11:30
Copy link

changeset-bot bot commented Oct 4, 2024

🦋 Changeset detected

Latest commit: cbd7549

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

@CPunisher CPunisher marked this pull request as draft October 4, 2024 11:55
Copy link

codspeed-hq bot commented Oct 4, 2024

CodSpeed Performance Report

Merging #9617 will create unknown performance changes

Comparing CPunisher:fix/replace-seq-assignment (cbd7549) with main (4436621)

Summary

🆕 194 new benchmarks

Benchmarks breakdown

Benchmark main CPunisher:fix/replace-seq-assignment Change
🆕 es/full/bugs-1 N/A 520.9 µs N/A
🆕 es/full/minify/libraries/antd N/A 4.1 s N/A
🆕 es/full/minify/libraries/d3 N/A 815.6 ms N/A
🆕 es/full/minify/libraries/echarts N/A 3.3 s N/A
🆕 es/full/minify/libraries/jquery N/A 202.5 ms N/A
🆕 es/full/minify/libraries/lodash N/A 249.8 ms N/A
🆕 es/full/minify/libraries/moment N/A 123.3 ms N/A
🆕 es/full/minify/libraries/react N/A 36.8 ms N/A
🆕 es/full/minify/libraries/terser N/A 624.2 ms N/A
🆕 es/full/minify/libraries/three N/A 1.3 s N/A
🆕 es/full/minify/libraries/typescript N/A 6.6 s N/A
🆕 es/full/minify/libraries/victory N/A 1.9 s N/A
🆕 es/full/minify/libraries/vue N/A 291.7 ms N/A
🆕 es/oxc/benches/assets/UserSettings.tsx/sourceMap=false/reactDev=false N/A 1.2 ms N/A
🆕 es/oxc/benches/assets/UserSettings.tsx/sourceMap=false/reactDev=true N/A 1.4 ms N/A
🆕 es/oxc/benches/assets/UserSettings.tsx/sourceMap=true/reactDev=false N/A 1.5 ms N/A
🆕 es/oxc/benches/assets/UserSettings.tsx/sourceMap=true/reactDev=true N/A 1.7 ms N/A
🆕 es/oxc/benches/assets/parser.ts/sourceMap=false/reactDev=false N/A 80.5 ms N/A
🆕 es/oxc/benches/assets/parser.ts/sourceMap=false/reactDev=true N/A 80.8 ms N/A
🆕 es/oxc/benches/assets/parser.ts/sourceMap=true/reactDev=false N/A 109.9 ms N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@kdy1
Copy link
Member

kdy1 commented Oct 7, 2024

Is collecting initial types enough? I think it can be useful for const but not for others

@CPunisher CPunisher force-pushed the fix/replace-seq-assignment branch from 27af2aa to fe683cf Compare October 11, 2024 14:33
@CPunisher CPunisher marked this pull request as ready for review October 12, 2024 06:48
@CPunisher
Copy link
Member Author

@kdy1 What do you think of this implementation? This looks more sound than the main branch at the cost of losing some completeness (some cases that can be optimized are not).

@kdy1
Copy link
Member

kdy1 commented Oct 13, 2024

I think it's quite a clever idea. Yeah, we have a merging function for merging characteristics of variables, and reusing it for types make sense I think.

@kdy1 kdy1 requested a review from a team as a code owner October 14, 2024 00:55
@kdy1 kdy1 added this to the Planned milestone Oct 14, 2024
@kdy1 kdy1 merged commit 4436621 into swc-project:main Oct 14, 2024
23 of 24 checks passed
@kdy1 kdy1 modified the milestones: Planned, v1.7.36 Oct 15, 2024
@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 15, 2024
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.

Minifier should check type of assignment target before merging assignments
2 participants