swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.26k stars 1.23k forks source link

feat(es/minifier): Optimize switch with side effect and termination tests #9677

Closed CPunisher closed 3 weeks ago

CPunisher commented 4 weeks ago

Description:

This is learnt from https://github.com/terser/terser/pull/1044 Key point: all the cases (statements) after the last side-effect and non-terminated one are useless.

There are also some points on whether a statement is side-effect free:

This is an existing bug. I'm not sure whether we should fix it since it is a very bad code and I also find some similar bad cases with terser.

~I'm also not sure it's appropriate to introduce context variable in_strict for StmtExt:: may_have_side_effects, because in_strict could change from false to true. But this is a conservative mistake and does not break the program. Maybe we should use visitor for context-aware side effect checker in the future.~

Related issue:

changeset-bot[bot] commented 4 weeks ago

🦋 Changeset detected

Latest commit: e13be3e24a8d71435d310727eebb1075ece38824

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

codspeed-hq[bot] commented 4 weeks ago

CodSpeed Performance Report

Merging #9677 will improve performances by 4.91%

Comparing CPunisher:feat/switch-side-effect (e13be3e) with main (2bbd1e8)

Summary

⚡ 1 improvements ✅ 193 untouched benchmarks

Benchmarks breakdown

Benchmark main CPunisher:feat/switch-side-effect Change
es/full/bugs-1 548 µs 522.4 µs +4.91%