Repository navigation
Add a WebAssembly build with threads for pages that are cross-origin isolated - #226
Merged
Merged
Conversation
nyosegawa
force-pushed
the
wasm-threads
branch
from
November 20, 2026 16:47
0e7f45e to
0701a88
Compare
Owner
Author
|
Checked outside CI, on an Apple M5 (macOS 26.2, 10 logical processors) with Emscripten 7.0.0 and this branch at 0701a88:
|
…isolated SPEECH_WASM_THREADS builds libspeech-threads.js and libspeech-threads.wasm, every file compiled with -pthread, whose memory is a SharedArrayBuffer that a browser gives only a page served with COOP and COEP. The module starts a Worker for each of the browser's logical processors before it runs, since ggml starts its threads for each graph and waits for them within the call, before a Worker asked for then could start; the library refuses more threads than that at speech_load_params_set_threads(), and a thread past them fails to start rather than waits. It computes on 4 threads by default: Silero VAD on a minute of audio ran its first request at RTFx 560 with 4 threads and 100 with all 10 of an Apple M5. Its memory grows to 1 GB at most, since Safari on iOS counts a shared memory's most against the process as it makes it and has refused one of 2 GB. speech.mjs loads either module and refuses the one with threads in a page that is not isolated; the page has a field of threads and runs the module with threads for more than one; wasm/serve.py serves the folder with both headers. The smoke takes --threads N and then checks that audio past the module's 1 GB is refused as out_of_memory before the module writes it, and that the module answers after it. A new record says why there are two modules, why the Workers start first, and why 4 threads and 1 GB; the platform record and docs/browser.md describe both, with their numbers. Checked: wasm_browser_smoke.mjs on the seven WAVE files with the module without threads, with --threads 4 and from one folder holding both with --threads 2: every region equal to speech vad's, 11 threads refused on 10 logical processors, audio of 1.08 GB refused (the check fails with "offset is out of bounds" when speech.mjs does not check malloc()). The page in Safari on the iOS 26.5 simulator with 4 threads: cross-origin isolated, the same regions. speech-api-check detect with Silero VAD and a native build. Apple M5, macOS 26.2, Chrome 158, Emscripten 7.0.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nyosegawa
force-pushed
the
wasm-threads
branch
from
November 20, 2026 16:59
0701a88 to
94d070c
Compare
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.
Builds on #225 (base
wasm-build, built on f3a6280).What changed
A second WebAssembly module, with threads, for pages that are cross-origin isolated.
emcmake cmake -B build-wasm-threads -DSPEECH_WASM_THREADS=ONbuildslibspeech-threads.jsandlibspeech-threads.wasm, every file compiled with-pthread. Its memory is a SharedArrayBuffer, which a browser gives only to a page served withCross-Origin-Opener-Policy: same-originandCross-Origin-Embedder-Policy: require-corp.PTHREAD_POOL_SIZE=navigator.hardwareConcurrency): ggml starts its threads for each graph and waits for them within the call, before a Worker asked for then could start. The library refuses more threads than that atspeech_load_params_set_threads(), and withPTHREAD_POOL_SIZE_STRICT=2a thread past them fails to start rather than waits.speech.mjs:openSpeech({ threads: true })loads the module with threads and refuses a page that is not isolated. The page has a Threads field (and&threads=Nin a link) and runs the module with threads for more than one.wasm/serve.pyserves the folder on 127.0.0.1 with both headers.--threads N, and then also checks that audio past the module's 1 GB is refused asout_of_memorybefore the module writes it (the review's finding on Build the C API for WebAssembly and run Silero VAD in a browser #225, which needs a module whose memory cannot grow), and that the next request answers.docs/browser.mddescribes both modules, their limits and numbers; c-api.md and the header give the threads of each; install.md's build table. ADRs: a new record of the threads module's decisions; the platform and Worker records mention it.Numbers
Silero VAD F32, a minute of audio, Apple M5 (10 logical processors), macOS 26.2, headless Chrome 158, Emscripten 7.0.0, 2026-11-21, medians of three runs:
libspeech.wasmand.jsgzippedspeech vadnatively: RTFx 660 with one thread, 1220 with four.Checked
wasm_browser_smoke.mjson seven WAVE files with the module without threads, with--threads 4, and from one folder holding both with--threads 2: every region equal tospeech vad's, 11 threads refused on 10 logical processors, 1.08 GB of audio refused asout_of_memory. Without the allocation check inspeech.mjsthat last check fails with "offset is out of bounds".speech-api-check detectwith Silero VAD.🤖 Generated with Claude Code