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

feat(es/minifier): Reuse variable names #4475

Closed
wants to merge 47 commits into from

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Apr 29, 2022

Description:

  • Node APIs (from google closure compiler)

  • Control flow graph

  • DataFlow analyzer

This has some TODOs left

  • Liveness analyzer

  • Coalesce variable names pass

Related issue (if exists):

@kdy1 kdy1 added this to the Planned milestone Apr 29, 2022
@kdy1 kdy1 force-pushed the minifier-reuse branch 2 times, most recently from 2734608 to 2abe295 Compare April 29, 2022 05:59
@kdy1
Copy link
Member Author

kdy1 commented Apr 29, 2022

@Austaras Can you describe more about reusing variable names in #2934 (comment) ?
I tried implementing it but seems like the size difference is too small.

One thing I found from diffing is reuse of variables in non-first statements, like

// lots of code

var a = b + b;

for (var d = init;) {
    use(d)
}

became

// lots of code

var a = b + b;

for (b = init;) {
    use(b)
}

but, I'm curious if there was more renaming. (I didn't analyze fully yet)

@Austaras
Copy link
Member

Austaras commented Apr 29, 2022

Seems like it's not really about initializer, but about reference

function hello(name) {
  console.log('Hello, ' + name);
  var b = window.a
  console.log(b === b)
}

be turned into

function hello(a) {
  console.log("Hello, " + a);
  a = window.a;
  console.log(a === a);
}

so a is not referred after var b declaration, so it can be reused

@kdy1
Copy link
Member Author

kdy1 commented Apr 29, 2022

Thank you!

@kdy1 kdy1 force-pushed the minifier-reuse branch 5 times, most recently from 68a194e to c0055c1 Compare May 5, 2022 05:36
@kdy1 kdy1 modified the milestones: Planned, v1.2.199 Jun 11, 2022
@kdy1 kdy1 modified the milestones: Planned, v1.2.210 Jul 5, 2022
@kdy1
Copy link
Member Author

kdy1 commented Sep 8, 2022

Closing in favor of #5781

@kdy1 kdy1 closed this Sep 8, 2022
@kdy1 kdy1 deleted the minifier-reuse branch September 8, 2022 04:00
@kdy1 kdy1 modified the milestones: Planned, v1.2.249 Sep 8, 2022
@kdy1 kdy1 restored the minifier-reuse branch September 8, 2022 14:03
@kdy1 kdy1 deleted the minifier-reuse branch September 10, 2022 04:06
@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

None yet

2 participants