-
Notifications
You must be signed in to change notification settings - Fork 63
Multithreaded WASM build: -sPTHREAD_POOL_SIZE too low for multi-engine apps #363
Description
Problem
The multithreaded WASM build (@ladybugdb/wasm-core/multithreaded) exhausts the Emscripten thread pool when running alongside other WASM engines (DuckDB-WASM, WebLLM) in the same browser tab.
Console output:
[LadybugDB] OPFS mounted at /persist
Tried to spawn a new thread, but the thread pool is exhausted.
This might result in a deadlock unless some threads eventually exit or the code explicitly breaks out to the event loop.
If you want to increase the pool size, use setting `-sPTHREAD_POOL_SIZE=...`.
Context
Our application runs three WASM engines concurrently in one browser tab:
- DuckDB-WASM (geospatial SQL queries)
- WebLLM (in-browser LLM inference via WebGPU)
- LadybugDB-WASM (graph database)
OPFS persistence (PR #360) works correctly — the mount succeeds. But when LadybugDB tries to spawn threads for database operations, the browser's pthread pool is already partially consumed by the other engines, causing exhaustion and deadlock.
Reproduction
- Load DuckDB-WASM + WebLLM in the same page
- Import
@ladybugdb/wasm-core/multithreaded - Mount OPFS:
await fs.mountOpfs('/persist') - Create a database:
new lbug.Database('/persist/db')— thread pool exhaustion
Suggested Fix
Increase -sPTHREAD_POOL_SIZE in the multithreaded CMake build configuration (currently defaults to Emscripten's default of 4). A value of 8-12 would accommodate multi-engine browser applications.
Alternatively, consider making it configurable at runtime or using -sPTHREAD_POOL_SIZE_STRICT=0 to allow dynamic growth.
Environment
@ladybugdb/wasm-corev0.15.4-dev.1 (April 3 nightly, includes PR fix: gate -lopfs.js behind pthreads to fix OPFS crash #360)- Chrome 135 on Windows 11
- COOP/COEP headers enabled
- SharedArrayBuffer available
Related
- PR fix: gate -lopfs.js behind pthreads to fix OPFS crash #360 (OPFS fix) — merged, working
- Discussion OPFS support for LadybugDB Wasm ? #305 (OPFS persistence tracking)