Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 43 additions & 26 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,39 @@ Do not infer the full application matrix from a timer or TLS witness.
- **Asyncify's stack is measured, not guessed.** `-sASYNCIFY_STACK_SIZE`
is 8192 unless a program raises it with `<asyncify-stack-size>`, declared
in `build.jam`: twice 4096, the smallest power of two with which every
test passed in every build b2 links today (2026-10-11, Emscripten 6.0.11).
The deepest is release, compiled with `-O3` and linked without
optimization, as b2's emscripten toolset links it: 3,540 bytes in
`bridge_asyncify`, against 1,272 in a debug build. Linked with `-O3`, the
deepest test wrote 416 and the run family's deepest path 384, against
2,404 linked without. The asyncify lane builds debug alone, so the
measurement covers the other builds itself: the bytes are read from
Asyncify's own data when an unwind stops, and `asyncify_stack` does it in
debug, release and release linked with `-O3`, for every suspension of the
run family, failing when one leaves less than half of the stack. A change
that adds a way to suspend (a coroutine's, a promise's) measures it there,
and a test that overflows traps with `RuntimeError: unreachable`, every
time. When b2's release link gets its `-O`, measure again: the deepest
build becomes debug's.
test passed in every build b2 linked on 2026-10-11 (Emscripten 6.0.11),
when the deepest was release, compiled with `-O3` and linked at `-O0`:
3,540 bytes in `bridge_asyncify`, against 1,272 in a debug build. Since
2026-11-15 b2 links release at `-O3`, and the deepest build is debug,
compiled and linked at `-O0`: the run family's deepest path wrote 1,168
bytes there and 388 in release (848 and 304 without exceptions), and with
2048 bytes no test of the asyncify lane trapped in either build, so that
the 2026-10-11 rule alone would now give 4096. The owner decided on
2026-11-15 that it stays 8192: programs ship release builds, where the
deepest suspension of the libraries built on asio wrote 564 bytes
(trystero's room test), leaving the rest to the program's own frames;
debug, for development and the tests, reached 2,344, within the half
`asyncify_stack` asks; and 8192 is the default and the floor those
libraries and their programs are tested against, so that a smaller size
would make a program whose frames above `run` fit only the larger stack
trap. The asyncify lane builds
debug alone, so the measurement covers release itself: the bytes are read
from Asyncify's own data when an unwind stops, and `asyncify_stack` does
it in debug and in release, for every suspension of the run family,
failing when one leaves less than half of the stack. A change that adds a
way to suspend (a coroutine's, a promise's) measures it there, and a test
that overflows traps with `RuntimeError: unreachable`, every time.
- **The stack test must reach the intended wait.** Its reactor cases hold
work until a JavaScript macrotask posts the completing handler, delay entry
by 25 ms and require a nonzero-timeout poll. An already-expired C++ timer
can suspend in the initial poll without reaching the deeper wait. The
test reads `doPollAsync` as well as Asyncify's private runtime; a runtime
change that removes either observation must fail rather than skip it.
The 2026-10-14 re-review measured maxima of 1164/844 bytes in debug,
2896/1940 in release and 384/288 in release linked with `-O3`, with/without
exceptions respectively. `run_until` has its own yield measurement too.
2896/1940 in release, then linked at `-O0`, and 384/288 in release linked
with `-O3`, with/without exceptions respectively; on 2026-11-15, with
release linked at `-O3`, 1168/848 in debug and 388/304 in release.
`run_until` has its own yield measurement too.
- **The run family is called on `main`'s stack alone**, or on the stack of
another export the program lists for suspension. Anywhere else its first
suspension fails: under JSPI it throws a `SuspendError`, and under
Expand Down Expand Up @@ -148,16 +158,23 @@ remains applicable without exceptions.
The Cobalt stack probe measures real Asyncify unwinds from the runner through
the yield, a Cobalt timer wait and an Asio timer wait. The timer waits cannot
expire: only a JavaScript macrotask posts their cancellation, so the test must
reach a blocking reactor poll. Measurements on 2026-10-14, Emscripten 6.0.11:

| Build | Exceptions | Yield bytes | Cobalt wait bytes | Asio wait bytes |
| --- | --- | ---: | ---: | ---: |
| Debug | on | 1016 | 1032 | 1032 |
| Debug | off | 684 | 700 | 700 |
| Release, default link | on | 968 | 1088 | 1088 |
| Release, default link | off | 748 | 956 | 956 |
| Release, link -O3 | on | 376 | 384 | 384 |
| Release, link -O3 | off | 228 | 228 | 228 |
reach a blocking reactor poll. Measurements with Emscripten 6.0.11 on
2026-10-14, when b2 linked a release build at `-O0` and the probe also built
release linked with `-O3`, and on 2026-11-15, once b2 linked release at
`-O3`, which left the probe a debug build and a release one:

| Date | Build | Exceptions | Yield bytes | Cobalt wait bytes | Asio wait bytes |
| --- | --- | --- | ---: | ---: | ---: |
| 2026-10-14 | Debug | on | 1016 | 1032 | 1032 |
| 2026-10-14 | Debug | off | 684 | 700 | 700 |
| 2026-10-14 | Release, link -O0 | on | 968 | 1088 | 1088 |
| 2026-10-14 | Release, link -O0 | off | 748 | 956 | 956 |
| 2026-10-14 | Release, link -O3 | on | 376 | 384 | 384 |
| 2026-10-14 | Release, link -O3 | off | 228 | 228 | 228 |
| 2026-11-15 | Debug | on | 1020 | 1036 | 1036 |
| 2026-11-15 | Debug | off | 688 | 704 | 704 |
| 2026-11-15 | Release | on | 376 | 384 | 384 |
| 2026-11-15 | Release | off | 232 | 232 | 232 |

The existing 8192-byte stack remains sufficient for these paths with more than
half free. These measurements are suspension storage, not binary sizes or a
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ and its artifacts keep the relative layout produced by `webcpp.variants`.
The documented binary-size table uses optimized release builds only. Build
both page variants and measure their uncompressed `.wasm` files with:

b2 -a toolset=emscripten variant=release cxxflags=-O3 linkflags=-O3 libs/asio/example//asyncify
b2 -a toolset=emscripten variant=release libs/asio/example//asyncify

The link flag is required because the current b2 Emscripten toolset does not
forward the compilation optimization level to the link. The guide records
A release build compiles and links at `-O3`: the superproject gives an
Emscripten link its compile's level of optimization, which b2's toolset
alone does not. Another level reaches both through `cxxflags` and
`linkflags`, the last level being the one `em++` keeps. The guide records
the toolchain and six profiles: `-O2`, `-O3`, `-Os`, `-Oz`, `-O3 -flto`
and `-Oz -flto`. It reports Wasm and JavaScript bytes separately for both
suspension variants, with exceptions on and off. It also records complete
Expand Down
26 changes: 18 additions & 8 deletions build.jam
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ include $(ASIO_SOURCE_DIR)/sources.jam ;
# where emcc keeps the last. Its values are powers of two; those below 8192
# are refused, by an #error of config.hpp that says why.
#
# 8192 is twice 4096, the smallest power of two with which every test of
# asio passed in every build b2 links today, measured on 2026-10-11 with
# Emscripten 6.0.11 as the bytes each unwind wrote. The deepest build is
# release, compiled with -O3 and linked without optimization, as b2's
# emscripten toolset links it: its deepest suspension wrote 3,540 bytes,
# against 1,272 in a debug build; Emscripten's default, 4096, left it 556,
# and with 2048 its tests trapped. Linked with -O3, the deepest test wrote
# 416 and the run family's deepest path 384, against 2,404 linked without.
# 8192 was set on 2026-10-11 as twice 4096, the smallest power of two with
# which every test of asio passed in every build b2 linked then, measured
# with Emscripten 6.0.11 as the bytes each unwind wrote: the deepest build
# was release, compiled with -O3 and linked at -O0, whose deepest suspension
# wrote 3,540 bytes, and with 2048 its tests trapped. Since 2026-11-15 b2
# links release at -O3, and debug, linked at -O0 as before, is the deepest
# build: asyncify_stack measured at most 1,168 bytes there and 388 in
# release (848 and 304 without exceptions), and with 2048 no test of the
# asyncify lane trapped in either build, so that rule alone would now give
# 4096. The owner decided on 2026-11-15 that it stays 8192. Programs ship
# release builds, where the deepest suspension of the libraries built on
# asio wrote 564 bytes (trystero's room test; asio's 388), so that the rest
# is left to the program's own frames, whose depth asio cannot know; debug,
# for development and the tests, reached 2,344 (the same test), within the
# half asyncify_stack asks. 8192 is also the default and the floor those
# libraries and their programs are tested against, and a smaller size would
# make a program whose frames fit only the larger stack trap at run time,
# with no warning before.
# The test asyncify_stack measures each build on every run, and fails when
# a suspension of the run family leaves less than half of the stack; a new
# way to suspend, such as a coroutine's, is measured there.
Expand Down
47 changes: 29 additions & 18 deletions doc/building.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,18 @@ enough". The trap is certain, at every suspension that deep, but only
there. So asio does not keep Emscripten's default: it sets the size to at
least twice the deepest suspension its tests reach, measured exactly, as
the bytes each unwind wrote, read from Asyncify's own data when the unwind
stops. In the measurements of 2026-10-11, the deepest build was one compiled
with optimization and linked without it, as b2's `release` variant links on emscripten:
its deepest suspension in the tests wrote 3,540 bytes, against 1,272 in a
`debug` build. Linked with optimization, a suspension writes a sixth or
less of what it writes linked without: 416 bytes at most in the tests, and 384
for the run family's deepest path, against 2,404. Half of the stack is so
left to the program's own frames, whose depth asio cannot know.
stops. The deepest build is `debug`, compiled and linked without
optimization: in the measurements of 2026-11-15, the run family's deepest
suspension wrote 1,168 bytes there, against 388 in a `release` build,
compiled and linked with `-O3`. The size, 8192 bytes, was set on
2026-10-11, when b2 linked a `release` build without optimization, then the
deepest build, whose deepest suspension in the tests wrote 3,540 bytes.
asio keeps it, as decided on 2026-11-15: programs ship `release` builds,
where the deepest suspension of the libraries built on asio wrote 564 bytes
(trystero's room test), so that nearly all of the stack is left to the
program's own frames, whose depth asio cannot know; it is the size those
libraries and their programs are tested against, and a smaller one would
make a program whose frames fit only the larger stack trap.

A program that calls `run` deep in its code, or whose frames above `run`
are large, measures its own suspensions the same way and asks for more
Expand All @@ -223,8 +228,8 @@ Nothing of the program runs afterwards: no destructor or `atexit` handler,
no timer or event of asio's; only JavaScript of the page's own that calls
an export could still enter it.

_Held by_ `asyncify_stack`, with exceptions and without them, in debug,
in release and in release linked with `-O3`, which measures every
_Held by_ `asyncify_stack`, with exceptions and without them, in debug
and in release, whatever variant the build asks for, which measures every
suspension of the run family, the reactor's wait and the yield under each
member that makes one, inside a `try` and a `catch` block too, and fails
when one of them leaves less than half of the stack, or when the reading
Expand All @@ -246,20 +251,26 @@ nonblocking poll: that poll suspends too, but its shorter stack is not
evidence for the waiting path. The yield cases cover `run`, `run_for` and
`run_until` separately.

On 2026-10-14, with Emscripten 6.0.11 and Node 26.7.0, the corrected
`asyncify_stack` test measured these maxima from scratch, in bytes:
With Emscripten 6.0.11, the corrected `asyncify_stack` test measured these
maxima from scratch, in bytes: on 2026-10-14, with Node 26.7.0, when b2
linked a `release` build without optimization and the test built a release
one linked with `-O3` besides, and on 2026-11-15, with Node 26.13.0, once
b2 linked a `release` build with `-O3`:

[cols="2,1,1",options="header"]
[cols="1,2,1,1",options="header"]
|===
| Build | Exceptions on | Exceptions off
| Debug | 1164 | 844
| Release, unoptimized link | 2896 | 1940
| Release, link with `-O3` | 384 | 288
| Date | Build | Exceptions on | Exceptions off
| 2026-10-14 | Debug | 1164 | 844
| 2026-10-14 | Release, linked without optimization | 2896 | 1940
| 2026-10-14 | Release, linked with `-O3` | 384 | 288
| 2026-11-15 | Debug | 1168 | 848
| 2026-11-15 | Release, linked with `-O3` | 388 | 304
|===

Each of the eleven paths with exceptions and nine without stayed below
4096 bytes, half of the configured 8192. These are measurements of the
run-family test, not a bound on a user's own call frames.
4096 bytes, half of the configured 8192, in every build. These are
measurements of the run-family test, not a bound on a user's own call
frames.

The artifacts are named and placed as Boost's own build names and places
them: one directory level per toolset, variant and property that is not
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changes prepared for the first WebCPP release.
* Improved exception analysis of system executor initialization without changing fatal behavior.
* Fixed posted completions after JavaScript reentry with concurrency hint one.
* Added current example coverage and Release performance, memory and yield measurements.
* Updated the guides and Asyncify stack measurements for release builds linked at `-O3`.
// end::unreleased[]

[#asio-changelog-0-1-0]
Expand Down
11 changes: 7 additions & 4 deletions doc/cobalt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ b2 toolset=emscripten libs/cobalt/test//cobalt_asyncify
----

The historical 2026-10-14 Asyncify probe measured a maximum of 1,088 bytes in
Release with the default link, 384 with an optimized link, and 1,032 in Debug.
These describe the earlier source revision. They are suspension storage, not
binary size or a bound on arbitrary application call depth. Current migration
measurements must be recorded separately; the configured stack remains 8,192 bytes.
Release, then linked without optimization, 384 in Release linked with `-O3`,
and 1,032 in Debug. These describe the earlier source revision. Since
2026-11-15 a Release build links at `-O3`, and Cobalt's `cobalt_stack` probe
measured at most 384 bytes in Release and 1,036 in Debug with exceptions,
232 and 704 without them, on that day, with Emscripten 6.0.11. They are
suspension storage, not binary size or a bound on arbitrary application call
depth; the configured stack remains 8,192 bytes.

[#asio-cobalt-sizes]
=== Historical reference: release binary sizes
Expand Down
19 changes: 11 additions & 8 deletions doc/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ b2 toolset=emscripten libs/asio/test libs/asio/example
asyncify::
A lane of asio's own, on emscripten: every browser test again under
Asyncify, the other suspension variant. Generate the size table separately
in optimized release mode, then execute the guide examples under Asyncify:
in release, which compiles and links at `-O3`, then execute the guide
examples under Asyncify:
+
[source,bash]
----
b2 toolset=emscripten libs/asio/test//asyncify
b2 -a toolset=emscripten variant=release linkflags=-O3 libs/asio/example//asyncify
b2 -a toolset=emscripten variant=release libs/asio/example//asyncify
b2 toolset=emscripten webcpp-suspend=asyncify libs/asio/example
----

Expand Down Expand Up @@ -212,12 +213,14 @@ for profile in o2 o3 os oz o3-lto oz-lto; do
done
----

`variant=release` supplies `NDEBUG` and disables debug symbols. The explicit
`cxxflags` selects the optimization level instead of the release default
`-O3`; the same level must be passed through `linkflags` for Emscripten's
final WebAssembly and JavaScript optimization. The current b2 toolset does
not forward it automatically. Keep separate build directories: free-form
flags do not select separate output paths in b2.
`variant=release` supplies `NDEBUG`, disables debug symbols, and compiles
and links at `-O3`: the superproject gives an Emscripten link its compile's
level of optimization, which b2's toolset alone does not. The explicit
`cxxflags` selects another level for the compile, and the same level passed
through `linkflags` selects it for Emscripten's final WebAssembly and
JavaScript optimization, since `em++` keeps the last level it is given.
Keep separate build directories: free-form flags do not select separate
output paths in b2.

`-O2` and `-O3` favor execution performance; `-Os` and `-Oz` favor smaller
code. `-flto` enables link-time optimization across translation units and
Expand Down
20 changes: 9 additions & 11 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ for local test in $(browser-tests)
.asyncify += $(test)_asyncify $(test)_asyncify_no_exceptions ;
}

# An optimized JSPI link must retain the native stack helpers used by the
# bridge's JavaScript. Debug runtime dependencies can hide missing exports.
# The bridge's JavaScript calls native stack helpers that a release link, at
# -O3, drops unless asio exports them (build.jam). A debug link, at -O0,
# keeps more of the runtime, which can hide a missing one, and the emscripten
# lane builds debug, b2's default: these build the bridge in release there.
for local handling in on off
{
webcpp.run bridge_optimized_link_exceptions_$(handling) : bridge_test.cpp
: <variant>release <linkflags>-O3 <exception-handling>$(handling)
: emscripten ;
webcpp.run bridge_release_exceptions_$(handling) : bridge_test.cpp
: <variant>release <exception-handling>$(handling) : emscripten ;
}

# Through the bridge, a program can neither deliver an event outside the
Expand Down Expand Up @@ -183,14 +184,11 @@ webcpp.run exceptions_asyncify : exceptions_test.cpp

# Each suspension of the run family under Asyncify leaves half of the stack
# Asyncify saves it in, measured exactly, with exceptions and without them,
# in each build a program can get: debug; release, compiled with -O3 and
# linked as b2's emscripten toolset links it, without optimization, which
# Asyncify instruments unoptimized; and release linked with -O3, as a
# product's link would be.
.asyncify-stack-builds = debug release optimized_link ;
# in each build a program can get, whatever variant the lane builds: debug,
# compiled and linked at -O0, the deepest, and release, at -O3.
.asyncify-stack-builds = debug release ;
.asyncify-stack-debug = <variant>debug ;
.asyncify-stack-release = <variant>release ;
.asyncify-stack-optimized_link = <variant>release <linkflags>-O3 ;
for local build in $(.asyncify-stack-builds)
{
for local handling in on off
Expand Down
3 changes: 2 additions & 1 deletion test/browser/worker_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
isolated: crossOriginIsolated, status: null, warnings: [], polls: []})
window.Module = {
preRun: [() => {
if (new URLSearchParams(location.search).get('script').includes('worker_return')) return
// Neither program polls, as run.mjs expects; a release link drops doPollAsync from such a program.
if (/worker_return|move_failure/.test(new URLSearchParams(location.search).get('script'))) return
if (typeof doPollAsync !== 'function') throw new Error('missing pinned SDK doPollAsync')
const original = doPollAsync
doPollAsync = (descriptors, count, timeout) => {
Expand Down
Loading