Skip to content

Feat/async thread pool#387

Open
sinui0 wants to merge 5 commits into
devfrom
feat/async-thread-pool
Open

Feat/async thread pool#387
sinui0 wants to merge 5 commits into
devfrom
feat/async-thread-pool

Conversation

@sinui0
Copy link
Copy Markdown
Collaborator

@sinui0 sinui0 commented May 5, 2026

Closes #371

Replaces the per-task thread-spawning model in mpz-common with a single shared work-stealing async executor. Each task is an async future that owns a deterministic I/O channel; idle workers steal across each other so a long-running task can't pin work on its creator's thread.

  • New Executor (built on crossbeam-deque injector + per-worker queues + async_task).
    ExecutorBuilder configures num_threads, prefix, and a custom worker spawn callback (std::thread::spawn by default; web_spawn::spawn on wasm).
  • try_join / try_join3 / try_join4 use futures::future::try_join* directly. Closure shape for join / try_join* / map is now for<'a> FnOnce(&'a mut Context) -> BoxFuture<'a, R>.
  • Context::map no longer takes a weight closure (load balancing is gone with the new executor).
  • Removed: Multithread/MultithreadBuilder/Spawn plumbing, mt/ and st.rs modules,
    load_balance.rs, and Counter.

@sinui0 sinui0 requested a review from th4s May 5, 2026 18:21
@sinui0
Copy link
Copy Markdown
Collaborator Author

sinui0 commented May 5, 2026

@th4s here is what I had in mind.

We should integration test this with tlsn and make sure there are no performance regressions. I would appreciate if you took over this PR

@th4s
Copy link
Copy Markdown
Contributor

th4s commented May 6, 2026

Yeah I will take over.

@th4s
Copy link
Copy Markdown
Contributor

th4s commented May 12, 2026

very nice 👍

I get some decent regression in the browser when testing with the tlsn harness: Seems to be a flat 0.3-0.4 seconds extra offset.

TLSNotary Benchmark Harness: Native (main: 040c6881...)
Running benchmarks from: bench.toml
Output will be written to: metrics.csv

[00:01:07] ████████████████████████████████████████ 18/18 Benchmarks complete
================================================================================
TLSNotary Benchmark Results
================================================================================

cable_mpc [mpc] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  14.46s

cable_proxy [proxy] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  1.59s

fiber_mpc [mpc] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  3.62s

fiber_proxy [proxy] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  0.93s
--------------------------------------------------------------------------------

TLSNotary Benchmark Harness: Native (feat/async-threadpool-integration: 6b0f0338...)
Running benchmarks from: bench.toml
Output will be written to: metrics.csv

[00:01:07] ████████████████████████████████████████ 18/18 Benchmarks complete
================================================================================
TLSNotary Benchmark Results
================================================================================

cable_mpc [mpc] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  14.50s

cable_proxy [proxy] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  1.63s

fiber_mpc [mpc] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  3.61s

fiber_proxy [proxy] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  0.96s
--------------------------------------------------------------------------------

TLSNotary Benchmark Harness: Browser (main: 040c6881...)
Running benchmarks from: bench.toml
Output will be written to: metrics.csv

[00:01:23] ████████████████████████████████████████ 18/18 Benchmarks complete
================================================================================
TLSNotary Benchmark Results
================================================================================

cable_mpc [mpc] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  15.61s

cable_proxy [proxy] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  2.06s

fiber_mpc [mpc] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  4.82s

fiber_proxy [proxy] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  1.35s
--------------------------------------------------------------------------------

TLSNotary Benchmark Harness: Browser (feat/async-threadpool-integration: 6b0f0338...)
Running benchmarks from: bench.toml
Output will be written to: metrics.csv

[00:01:26] ████████████████████████████████████████ 18/18 Benchmarks complete
================================================================================
TLSNotary Benchmark Results
================================================================================

cable_mpc [mpc] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  16.09s

cable_proxy [proxy] (20 Mbps, 20ms latency, 1KB↑ 2KB↓):
  Median:  2.40s

fiber_mpc [mpc] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  5.14s

fiber_proxy [proxy] (100 Mbps, 15ms latency, 1KB↑ 2KB↓):
  Median:  1.68s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Utilize thread pools

2 participants