Skip to content

Consolidate acorn_optimizer calls in minify_wasm_js. NFC - #27928

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:consolidate-acorn-optimizer
Oct 8, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:consolidate-acorn-optimizer

Conversation

@sbc100

@sbc100 sbc100 commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Previously, at -O3/-Os/-Oz (expensive_optimizations), minify_wasm_js invoked acorn-optimizer.mjs up to four separate times to parse and reprint JS:

  1. Pre-metadce (AJSDCE, stripDefaultUndefined, --minify-whitespace)
  2. Inside metadce (applyDCEGraphRemovals, --minify-whitespace)
  3. Post-metadce (AJSDCE, --minify-whitespace)
  4. Inside minify_wasm_imports_and_exports (applyImportAndExportNameChanges, --minify-whitespace)

Have metadce and minify_wasm_imports_and_exports return their removal/renaming metadata instead of invoking acorn_optimizer directly, and consolidate applyDCEGraphRemovals, post-metadce AJSDCE, applyImportAndExportNameChanges, stripDefaultUndefined, and --minify-whitespace into a single final acorn_optimizer pass.

Split out from #27926

@sbc100
sbc100 requested a review from kripken October 8, 2026 20:14
@sbc100
sbc100 force-pushed the consolidate-acorn-optimizer branch 2 times, most recently from 7875de7 to 13d8ad0 Compare October 8, 2026 20:41
Previously, at `-O3`/`-Os`/`-Oz` (`expensive_optimizations`),
`minify_wasm_js` invoked `acorn-optimizer.mjs` up to four separate times
to parse and reprint JS:
1. Pre-`metadce` (`AJSDCE`, `stripDefaultUndefined`,
   `--minify-whitespace`)
2. Inside `metadce` (`applyDCEGraphRemovals`, `--minify-whitespace`)
3. Post-`metadce` (`AJSDCE`, `--minify-whitespace`)
4. Inside `minify_wasm_imports_and_exports`
   (`applyImportAndExportNameChanges`, `--minify-whitespace`)

Have `metadce` and `minify_wasm_imports_and_exports` return their
removal/renaming metadata instead of invoking `acorn_optimizer`
directly, and consolidate `applyDCEGraphRemovals`, post-`metadce`
`AJSDCE`, `applyImportAndExportNameChanges`, `stripDefaultUndefined`,
and `--minify-whitespace` into a single final `acorn_optimizer` pass.
@sbc100
sbc100 force-pushed the consolidate-acorn-optimizer branch from 13d8ad0 to 171bccb Compare October 8, 2026 21:20
@sbc100
sbc100 requested a review from dschuff October 8, 2026 22:30
Comment thread tools/building.py
# now that we removed unneeded communication between js and wasm, we can
# clean up the js some more.
passes += ['applyDCEGraphRemovals', 'AJSDCE']
extra_info.update(dce_info)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why update()? extra_info is empty here, so we might as well do = dce_info - ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the idea is the extra_info can contains info for different passes at the same time. Yes, we know at this point in the code that no other pass has added extra info yet, but it seems good for future readers/editors if all changes to extra_info in this function addative and non-destructive.

(See below where minify_wasm_imports_and_exports adds to the extra_info).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough.

Comment thread tools/building.py
# now that we removed unneeded communication between js and wasm, we can
# clean up the js some more.
passes += ['applyDCEGraphRemovals', 'AJSDCE']
extra_info.update(dce_info)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough.

@sbc100
sbc100 merged commit e1413c3 into emscripten-core:main Oct 8, 2026
41 checks passed
@sbc100
sbc100 deleted the consolidate-acorn-optimizer branch October 8, 2026 23:37
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.

2 participants