-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
perf(es/minifier): Do not repeat applying pure minifier on last #10196
Conversation
🦋 Changeset detectedLatest commit: 071205b 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 |
@@ -51,10 +51,12 @@ export default function(c, a) { | |||
} | |||
}(c); | |||
if ("number" == typeof c && isFinite(c)) { | |||
; |
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.
Can someone help me fix the regression caused by this? We have
stmts.retain(|s| !matches!(s.as_stmt(), Some(Stmt::Empty(..)))); |
retain
cc @swc-project/core-es
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.
Understanding the traversal order remains challenging. A visualization tool that highlights AST node spans in the code editor during traversal, while logging corresponding visitor function locations, would be valuable. Implementing a step-through visualization that replays the traversal sequence within the editor interface could greatly enhance our debugging workflow.
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.
swc/crates/swc_ecma_minifier/src/compress/pure/vars.rs
Lines 250 to 255 in 08cd363
let mut v = VarMover { | |
target, | |
vars: Default::default(), | |
var_decl_kind: Default::default(), | |
}; | |
stmts.visit_mut_with(&mut v); |
The key point is that the VarMover here will delve deeper into the AST to modify code at nested inner layers, while our upper-layer visitor currently operates at the outer level.
export default function(a, c) { // <- Pure::Visit_mut_stmts
try {
if ("string" == typeof a && a.length > 0) return function(e) {
// ...
}(a);
if ("number" == typeof a && isFinite(a)) {
var r, n, t, o; // <- VarMover changed this
return (null == c ? void 0 : c.long) ? (r = a, (n = Math.abs(r)) >= 86400000 ? s(r, n, 86400000, "day") : n >= 3600000 ? s(r, n, 3600000, "hour") : n >= 60000 ? s(r, n, 60000, "minute") : n >= 1000 ? s(r, n, 1000, "second") : "".concat(r, " ms")) : (t = a, (o = Math.abs(t)) >= 86400000 ? "".concat(Math.round(t / 86400000), "d") : o >= 3600000 ? "".concat(Math.round(t / 3600000), "h") : o >= 60000 ? "".concat(Math.round(t / 60000), "m") : o >= 1000 ? "".concat(Math.round(t / 1000), "s") : "".concat(t, "ms"));
}
throw Error("Value is not a string or number.");
} catch (s) {
var u; // <- VarMover changed this
throw Error((void 0 === (u = s) ? "undefined" : e(u)) === "object" && null !== u && "message" in u ? "".concat(s.message, ". value=").concat(JSON.stringify(a)) : "An unknown error has occurred.");
}
}
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.
Understanding the traversal order remains challenging. A visualization tool that highlights AST node spans in the code editor during traversal, while logging corresponding visitor function locations, would be valuable. Implementing a step-through visualization that replays the traversal sequence within the editor interface could greatly enhance our debugging workflow.
Yeah, I love the idea, but I need to think about the way to implement it.
The key point is that the VarMover here will delve deeper into the AST to modify code at nested inner layers, while our upper-layer visitor currently operates at the outer level.
Yeap, thank you! I fixed it.
CodSpeed Performance ReportMerging #10196 will improve performances by 4.85%Comparing Summary
Benchmarks breakdown
|
### What? Applies swc-project/swc#10196 ### Why? swc-project/swc#10196 makes minification 3%~4% faster
Description:
This is mostly waste of time