Repository navigation
Enable toplevel: true in acorn-optimizer.mjs Terser pass - #27987
Conversation
Terser's `reduce_vars: true` inlines top-level `const` declarations into their use sites during `minify_sync`, which runs after `JSDCE`. Without `toplevel: true`, Terser's `unused: true` pass refuses to drop top-level declarations, leaving inlined top-level `const` declarations and other unused top-level variables in the output. This should really have been part of emscripten-core#27949.
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe optimizer now enables Terser top-level compression. Recorded JavaScript and support-module size baselines decrease, while recorded WASM sizes remain unchanged. ChangesCompression and size baselines
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
|
oops, coderabbit just reviews this change and auto-commit landed it. I guess we are in the future already. @kripken can you review this still please? |
|
Wait... is coderabbit a committer in this repo? Isn't that needed for lgtm to allow landing? (I don't think it should be a committer, if so) |
|
Is it necessary for Coderabbit to both modify the OP and also post a comment? Seems like only the latter would be preferable. |
|
There are a lot of options / settings we have for controlling that kind of thing. Right now I'm mostly concerned about the quality of reviews themselves not being as good as, e.g. gemini |
After `FS.filesystems` was removed in emscripten-core#27940 and `toplevel: true` was enabled for Terser in emscripten-core#27987, optional filesystem backends linked in via `-lidbfs.js`, `-lworkerfs.js`, `-lproxyfs.js`, `-lopfs.js`, etc. had no remaining references in the generated JS and were eliminated in `-O2` and `-O3` builds when referenced only from external JS (such as `Module.preRun` in HTML). Mark these optional filesystem backend objects with `__export: true` so that when `$FS` pulls them in, they are exported and preserved across JS optimizations (including `--closure=1`, `-sMODULARIZE`, and `-sMODULARIZE=instance`), without adding any code size when `$FS` is not used or under default settings. Fixes: emscripten-core#28072
After `FS.filesystems` was removed in emscripten-core#27940 and `toplevel: true` was enabled for Terser in emscripten-core#27987, optional filesystem backends linked in via `-lidbfs.js`, `-lworkerfs.js`, `-lproxyfs.js`, `-lopfs.js`, etc. had no remaining references in the generated JS and were eliminated in `-O2` and `-O3` builds when referenced only from external JS (such as `Module.preRun` in HTML). Mark these optional filesystem backend objects with `__export: true` so that when `$FS` pulls them in, they are exported and preserved across JS optimizations (including `--closure=1`, `-sMODULARIZE`, and `-sMODULARIZE=instance`), without adding any code size when `$FS` is not used or under default settings. Fixes: emscripten-core#28072
Terser's
reduce_vars: trueinlines top-levelconstdeclarations intotheir use sites during
minify_sync, which runs afterJSDCE. Withouttoplevel: true, Terser'sunused: truepass refuses to drop top-leveldeclarations, leaving inlined top-level
constdeclarations and otherunused top-level variables in the output.
This has negligible link-time performance impact (~1-3 ms on
minify_sync), sincereduce_varsandunusedalready walk the fullAST_Topleveltree regardless of thetoplevelsetting.This should really have been part of #27949.
Summary by CodeRabbit