Repository navigation
build: link emscripten programs at their compile's level of optimization - #18
Merged
Merged
Conversation
b2 5.5.3's emscripten toolset compiles at the level <optimization> names (-O3 in release, as gcc.jam maps it) and gives its link no level, which em++ runs at -O0: a release program was linked without optimization, so Binaryen's wasm-opt never ran on the whole module and Asyncify instrumented it unoptimized, saving whole frames at each suspension. The Jamroot now maps <optimization> to em++'s link options with toolset.flags on emscripten.link: off -O0, speed -O3, space -Os, minimal -O1, debug -Og. They are the toolset's own options, before <linkflags>, so a program that asks for another level still gets it, and they reach every program b2 links with em++, whatever project declares it. A debug build links as before (its outputs are byte-identical). Measured with Emscripten 6.0.11, asio's release timers test went from 735,400 bytes of .wasm to 489,216, and the deepest suspension of its asyncify_stack test from 2,900 bytes to 388 (1,900 to 304 without exceptions), the same as its optimized_link build. tools/test/emscripten_test.py checks the level of each value against the compile's, and that a program's own linkflags come last. AGENTS.md, CODING-GUIDELINES.md and the 0.1.0 release notes say so.
pinhopro
pushed a commit
that referenced
this pull request
Nov 15, 2026
Chapter 15's trystero entry keeps run_case as the rule, which keeps a test's cases out of main's frame whatever the link, and gives the measurements under the link the Jamroot now gives a release program, -O3: the room, app_impl and allocation tests' deepest suspensions write 564, 440 and 408 bytes in release and 2,344, 2,068 and 2,020 in debug, now the deepest build, and a main with every case inlined fits at -O3. The release runs stay as trystero's only runs under Asyncify in the CI's emscripten lane. Chapter 19's "Emscripten's release link." is removed: the Jamroot's link options fixed it (#18).
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
b2 5.5.3's emscripten toolset compiles each translation unit at the level
<optimization>names (-O3invariant=release) but passes no-Oto its link, which em++ then runs at-O0. Release programs were therefore linked without optimization: Binaryen's wasm-opt never ran on the whole module, and under Asyncify the instrumentation was applied to unoptimized code, saving whole frames at each suspension.What changes
Jamrootmaps<optimization>to em++'s link options withtoolset.flagsonemscripten.link(off-O0, speed-O3, space-Os, minimal-O1, debug-Og), in the regionemscripten-link-optimization. They are the toolset's own options, before<linkflags>, so a program that asks for another level still gets it.tools/test/emscripten_test.pygainstest_a_link_is_optimized_as_its_compile, which fails on main.AGENTS.md(chapter 4 Targets, chapter 6),CODING-GUIDELINES.mdand the 0.1.0 release notes describe it.Measured (Emscripten 6.0.11, release)
timers: 735,400 -> 489,216 bytes of.wasm;timers_asyncify: 2,481,578 -> 988,047.asyncify_stack, deepest unwind: 2,900 -> 388 bytes (1,900 -> 304 without exceptions), now identical to itsoptimized_linkbuild; cobalt's: 1,092 -> 384.Verification
test/no_exceptions/driver.pyexpects the ASSERTIONS-only abort textAborted(native code called abort()).test/browser/worker_page.htmlrequires Emscripten'sdoPollAsync, which the optimized link drops frombrowser_worker_move_failurebecause that program never polls.Follow-ups in the libraries: asio's
asyncify-stack-sizerationale and itsoptimized_linktests and docs, and cobalt'soptimized_linktests, describe the old link.🤖 Generated with Claude Code