Cap wasm worker pool growth#3
Merged
rlch merged 1 commit intoJun 26, 2026
Merged
Conversation
Add a hard maximum to the wasm-bindgen WorkerPool and queue additional work FIFO once all capped workers are busy. This keeps WorkerPool::new behavior compatible while exposing new_with_max for embedders that need lazy prewarm with a strict cap.\n\nOn wasm, execute Thread::Main normal/async calls inline instead of sending them through a worker pool, avoiding unnecessary worker creation for main-thread-safe work.
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.
Summary
Cap wasm
WorkerPoolgrowth and add an explicit lazy hard-cap constructor for web worker lanes.Problem
WorkerPool::new(Some(1), ...)prewarmed one worker, but did not enforce a maximum of one live worker. Under bursty FRB traffic, the pool could spawn additional workers and retain them.For embedders using FRB thread lanes as logical single-worker lanes, this meant a “single worker” lane could accidentally become a growing worker pool, increasing browser worker count and memory usage.
Changes
WorkerPool::new_with_max(initial, max_workers, ...).WorkerPool::new_raw_with_max(...).max_workersis reached.WorkerPool::new(...)API while making its worker count act as a hard cap.Thread::Mainnormal/async calls inline instead of dispatching them through a worker pool.Why
This allows embedders to create lanes like:
Meaning:
This is useful for strict single-threaded wasm lanes such as CRDT/Loro document access.
Validation
cargo fmt -p flutter_rust_bridgecargo check -p flutter_rust_bridge --target wasm32-unknown-unknown --features serde_json,uuid -q