-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(es/minifier): Remove inlined IIFE arg and param #11436
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
base: main
Are you sure you want to change the base?
Conversation
|
| param.id.ctxt | ||
| ); | ||
| vars.insert(param.to_id(), arg.clone()); | ||
| vars.insert(param.take().to_id(), arg.take()); |
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.
In the near future we should merge this with var inline.
CodSpeed Performance ReportMerging this PR will improve performance by 2.2%Comparing Summary
Performance Changes
|
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.
Pull request overview
This PR optimizes the IIFE (Immediately Invoked Function Expression) inlining process in the minifier by removing inlined arguments and parameters instead of cloning them. This improves both performance and code size by properly removing unused parameters and arguments after inlining their values into the function body.
Key changes:
- Replace
.clone()with.take()for arguments and parameters during IIFE inlining - Properly clean up invalid arguments and parameters after inlining
- Add comprehensive pattern validation to detect and remove dummy identifiers and invalid patterns
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/swc_ecma_minifier/src/compress/optimize/iife.rs | Core implementation: Changed from cloning to taking arguments/parameters when inlining IIFEs, added improved cleanup logic for invalid patterns |
| crates/swc_ecma_minifier/tests/terser/compress/reduce_vars/defun_inline_1/output.js | Test output: IIFE parameters and arguments properly removed after inlining |
| crates/swc_ecma_minifier/tests/terser/compress/reduce_vars/defun_inline_2/output.js | Test output: IIFE parameters and arguments properly removed after inlining |
| crates/swc_ecma_minifier/tests/terser/compress/hoist_props/name_collision_3/output.js | Test output: Unused IIFE parameters removed |
| crates/swc_ecma_minifier/tests/terser/compress/hoist_props/name_collision_2/output.js | Test output: Unused IIFE parameters removed |
| crates/swc_ecma_minifier/tests/terser/compress/hoist_props/direct_access_2/output.js | Test output: Unused IIFE parameters removed |
| crates/swc_ecma_minifier/tests/terser/compress/functions/issue_2657/output.js | Test output: Unused IIFE parameters removed |
| crates/swc_ecma_minifier/tests/terser/compress/evaluate/issue_2916_1/output.js | Test output: First parameter of IIFE removed after inlining |
| crates/swc_ecma_minifier/tests/projects/output/react-dom-17.0.2.js | Test output: Multiple IIFE parameters removed throughout large project file |
| crates/swc_ecma_minifier/tests/projects/output/jquery.mobile-1.4.2.js | Test output: IIFE parameters removed in production code |
| crates/swc_ecma_minifier/tests/fixture/next/wrap-contracts/output.js | Test output: IIFE parameters removed in Next.js fixture |
| crates/swc_ecma_minifier/tests/fixture/next/syncfusion/933-e9f9a6bf671b96fc/output.js | Test output: IIFE parameters removed in Syncfusion fixture |
| crates/swc_ecma_minifier/tests/fixture/next/react-pdf-renderer/output.js | Test output: IIFE parameters removed in React PDF renderer |
| crates/swc_ecma_minifier/tests/fixture/next/47005/output.js | Test output: IIFE parameters and unnecessary variable declarations removed |
| crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/output.js | Test output: IIFE parameters removed |
| crates/swc_ecma_minifier/tests/fixture/issues/react-countup/1/output.js | Test output: IIFE parameters removed in destructuring helpers |
| crates/swc_ecma_minifier/tests/fixture/issues/quagga2/1.4.2/1/output.js | Test output: IIFE parameters removed |
| crates/swc_ecma_minifier/tests/fixture/issues/firebase-firestore/1/output.js | Test output: IIFE parameters removed |
| crates/swc_ecma_minifier/tests/fixture/issues/firebase-core/1/output.js | Test output: IIFE parameters removed in destructuring helpers |
| crates/swc_ecma_minifier/tests/fixture/issues/emotion/react/1/output.js | Test output: IIFE parameters removed in destructuring helpers |
| crates/swc_ecma_minifier/tests/benches-full/victory.js | Test output: IIFE parameters removed in benchmark file |
| crates/swc_ecma_minifier/tests/benches-full/echarts.js | Test output: Multiple IIFE parameters removed throughout large benchmark file |
| crates/swc/tests/tsc-references/jsDeclarationsClasses.2.minified.js | Test output: IIFE with null superclass has parameter removed |
| crates/swc/tests/tsc-references/emitDefaultParametersFunctionExpressionES6.2.minified.js | Test output: Entire unused IIFE removed |
| crates/swc/tests/tsc-references/callNonGenericFunctionWithTypeArguments.2.minified.js | Test output: Variable declarations updated due to IIFE inlining |
| crates/swc/tests/tsc-references/callGenericFunctionWithZeroTypeArguments.2.minified.js | Test output: Variable declarations updated due to IIFE inlining |
| crates/swc/tests/fixture/issues-4xxx/4953/output/index.js | Test output: IIFE parentheses changed from () to !function pattern |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Binary Sizes
Commit: 4b0515b |
|
@claude Review this PR, |
|
Claude finished @kdy1's task in 2m 42s —— View job Code Review CompleteSummaryThis PR optimizes IIFE argument inlining by replacing Issues Found🔴 Critical: Span accessed after take() in rest parameter handlingLocation: The code takes vars.insert(
param_id.take().to_id(), // Line 264: param_id is taken here
ArrayLit {
span: param_id.span, // Line 266: PROBLEM - accessing span after take()
elems: e.args.iter_mut()...After Fix: Save the span before taking: let span = param_id.span;
vars.insert(
param_id.take().to_id(),
ArrayLit {
span, // Use saved span
elems: ...🟡 Minor: Inconsistent parameter handling for undefined argumentsLocation: When an argument is undefined (None), the code uses } else {
// No argument provided
vars.insert(param.to_id(), Expr::undefined(param.span())); // Doesn't take param
}But when an argument IS provided and inlined, it uses Fix: Take the param in all branches: } else {
let span = param.span();
vars.insert(param.take().to_id(), Expr::undefined(span));
}Positive Aspects✅ Performance improvement: The change from cloning to taking is a good optimization Minor Observations
Breaking Change NoteThe PR description mentions this is a breaking change but doesn't explain why. Based on the code changes, this appears to be an internal optimization that shouldn't break public APIs. The "breaking" aspect might refer to:
However, these are output changes not API changes. Consider clarifying in the PR description whether this is truly a breaking change or just an optimization. Recommendations
Test EvidenceThe test outputs look correct - for example, in // Before: function(b) { return 2; }(0)
// After: function() { return 2; }()The unused parameter Overall Assessment: Good performance optimization with one critical bug that needs fixing before merge. The approach is sound, but the span handling after |
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.
Pull request overview
Copilot reviewed 60 out of 60 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
crates/swc/tests/tsc-references/emitDefaultParametersFunctionExpressionES6.2.minified.js:2
- The entire IIFE call has been removed, leaving only the file header comment. This suggests that the IIFE had no side effects and was completely optimized away. However, this seems too aggressive - the original code likely had
!function(num, boo = !1) {}(0);which is a function call that should at least remain as a statement, even if it does nothing. Removing it entirely changes the semantics of the code.
//// [emitDefaultParametersFunctionExpressionES6.ts]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description:
BREAKING CHANGE:
Related issue (if exists):