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

extend fuzzy RHS folding #3006

Merged
merged 1 commit into from Mar 16, 2018
Merged

Conversation

alexlamsl
Copy link
Collaborator

  • a = []; if (1) x(); ➡️ if (a = []) x();

@kzc
Copy link
Contributor

kzc commented Mar 15, 2018

a = []; if (1) x(); ➡️ if (a = []) x();

Will this de-opt some code if the if could otherwise be simplified?

Or can this form:

if (a = []) x();

get to this form:

a=[];x();

with or without passes?

@alexlamsl
Copy link
Collaborator Author

I have yet to observe lost opportunities like that with the samples I'm testing, but theoretically a = [] is not being treated as truthy at the moment.

Shouldn't be too hard to make it happen in a separate PR.

@kzc
Copy link
Contributor

kzc commented Mar 15, 2018

Optimal code for this transform is dependent on the order of optimizations. Does default minify show an improvement generally?

@alexlamsl
Copy link
Collaborator Author

For test/benchmark.js, the major improvement is observed with lodash.js:

if (isArray(objValue)) {
    newValue = objValue;
}
else if (isArrayLikeObject(objValue)) {
    newValue = copyArray(objValue);
}
else if (isBuff) {
    isCommon = false;
    newValue = cloneBuffer(srcValue, true);
}
else if (isTyped) {
    isCommon = false;
    newValue = cloneTypedArray(srcValue, true);
}
else {
    newValue = [];
}

whereby the folding of isCommon = false; into true allows for all the newValue = to be extracted as a single assignment instead of multiple ones buried in a chain of conditionals.

@kzc
Copy link
Contributor

kzc commented Mar 15, 2018

That would be a good test for this PR.

@alexlamsl alexlamsl changed the title extend fuzzy RHS folding [WIP] extend fuzzy RHS folding Mar 15, 2018
- `a = []; if (1) x();` => `if (a = []) x();`
@alexlamsl alexlamsl changed the title [WIP] extend fuzzy RHS folding extend fuzzy RHS folding Mar 15, 2018
@alexlamsl
Copy link
Collaborator Author

That would be a good test for this PR.

Done in https://github.com/mishoo/UglifyJS2/pull/3006/files#diff-37dcf1d17b8a2b3c980e12edef17fdc8R5036

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants