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): calc function body cost when inline function #5342
Conversation
crates/swc_ecma_minifier/tests/terser/compress/functions/issue_2783/output.js
Outdated
Show resolved
Hide resolved
7f2fda0
to
9252b01
Compare
crates/swc_ecma_minifier/tests/fixture/issues/moment/1/output.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like lots of unrelated changes are in this PR.
Can you rebase again to drop them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should count variables or fix #5367 before merging this.
I can work on it if you prefer it
...fier/tests/fixture/next/feedback-util-promisify/chunks/pages/_app-72ad41192608e93a/output.js
Outdated
Show resolved
Hide resolved
..._ecma_minifier/tests/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/output.js
Outdated
Show resolved
Hide resolved
I reverted some |
I could start working on #5367 this evening or tomorrow |
Yes, to fix #5367 need to tinker anaylzer anyway.. |
Why does minifier has a seperate trait |
I made it because I wanted to create more cheaper analyzers without repeating work for I think it's fine to remove it. |
Will this fix #5404? |
All obstacles blocking this have been removed. I could restart this PR this weekend. |
1d85d96
to
a093045
Compare
Main:
This PR:
|
Regression in moment is because we inline big number literal which is fine, and I haven't investigated Typescipt because of its size. All other regerssions can be run down to a single issue export function foo(a) {
return bar(a) + bar(a)
}
function bar(a) {
return a + 1
} where simple functions(in this case, |
Oh... So we need one more pass. |
I'll create a PR to change default pass limit to 3 |
Maybe not an extra physical pass but something like |
I think it's now fine to run a full pass again so I made #6138 |
Now #6138 is merged. Can you rebase? |
Sure. I will rebase this and test it tonight. |
Three passes
The only regression is in |
break; | ||
case 'bottomleft': | ||
setPosx(getElementLeft(), pos), setPosy(getElementBottom(), pos); | ||
setPosx(getElementLeft(), pos), value7 = getElementBottom(), pos.top = value7; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a regresison. Are we considering the size of the member property correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We count pos.top = value
as size 7, as both pos
and value
can be mangled, and function call cost is 3 + param_count * 2 + 14 / callee_count
larger than 7, so it got inlined. This regression is caused by value
cannot be inlined, as pos.top
may have side effect. However we cannot know if an argument has side effect at the time of inlining since we only know it's declaration.
usage: &VarUsageInfo, | ||
) -> bool { | ||
let param_cost = param_count * 2; | ||
// if it's passed as value but not called, the function expr cannot be removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the case, couldn't we just return false and skip the work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function foo() {
g()
}
foo()
module.exports = foo
In this case foo
cannot be removed, but still can be inlined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still looking at changes, so this is just a bump comment
swc-bump:
- swc_ecma_minifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automated review comment generated by auto-rebase script
Description:
A follow up of #5253.
BREAKING CHANGE:
Related issue (if exists):