Skip to content

feat(core): configurable WASM worker thread count via EndpointFactory setup()#161

Merged
zurekz merged 3 commits into
develfrom
feat/wasm-worker-count
Apr 24, 2026
Merged

feat(core): configurable WASM worker thread count via EndpointFactory setup()#161
zurekz merged 3 commits into
develfrom
feat/wasm-worker-count

Conversation

@imaTik0
Copy link
Copy Markdown
Member

@imaTik0 imaTik0 commented Apr 17, 2026

AsyncEngine (C++):

  • Add EM_JS readWorkerCountFromJs() that reads window.__privmxWorkerCount
  • AsyncEngine() constructor reads the global and uses it as the thread-pool size (defaults to 4 when absent; enforces minimum of 2)

EndpointFactory (TypeScript):

  • setup() now accepts string | EndpointSetupOptions (backwards-compatible; a plain string assetsBasePath is still accepted)
  • New EndpointSetupOptions interface: { assetsBasePath?, workerCount? }
  • When workerCount is provided, sets window.__privmxWorkerCount before calling endpointWasmModule() so the C++ constructor reads it during WASM initialisation on the worker thread

Tests (E2E):

  • measureSendMessages() helper: reload page, call setup({ workerCount }), send N messages concurrently, return elapsed ms
  • "Worker count / EndpointFactory.setup() initialises WASM with the requested worker count": runs at 2/4/8/16 workers, logs timings
  • measureSignData() helper: same pattern using 200 concurrent signData calls (CPU-bound secp256k1, no network)
  • "Worker count scales CPU-bound crypto throughput": hard-asserts that 4w < 2w and 8w < 4w to verify the parameter actually controls parallelism
  • setup({ assetsBasePath }) object-form test: verifies connect + key derivation work end-to-end when using the new options object

@imaTik0 imaTik0 changed the title feat(core): configurable WASM worker thread count via EndpointFactory… feat(core): configurable WASM worker thread count via EndpointFactory setup() Apr 17, 2026
@imaTik0 imaTik0 marked this pull request as ready for review April 23, 2026 07:51
@imaTik0 imaTik0 changed the base branch from feat/refactor-driver-context to devel April 23, 2026 14:16
….setup()

AsyncEngine (C++):
- Add EM_JS readWorkerCountFromJs() that reads window.__privmxWorkerCount
- AsyncEngine() constructor reads the global and uses it as the thread-pool
  size (defaults to 4 when absent; enforces minimum of 2)

EndpointFactory (TypeScript):
- setup() now accepts string | EndpointSetupOptions (backwards-compatible;
  a plain string assetsBasePath is still accepted)
- New EndpointSetupOptions interface: { assetsBasePath?, workerCount? }
- When workerCount is provided, sets window.__privmxWorkerCount before
  calling endpointWasmModule() so the C++ constructor reads it during
  WASM initialisation on the worker thread

Tests (E2E):
- measureSendMessages() helper: reload page, call setup({ workerCount }),
  send N messages concurrently, return elapsed ms
- "Worker count / EndpointFactory.setup() initialises WASM with the
  requested worker count": runs at 2/4/8/16 workers, logs timings
- measureSignData() helper: same pattern using 200 concurrent signData
  calls (CPU-bound secp256k1, no network)
- "Worker count scales CPU-bound crypto throughput": hard-asserts that
  4w < 2w and 8w < 4w to verify the parameter actually controls parallelism
- setup({ assetsBasePath }) object-form test: verifies connect + key
  derivation work end-to-end when using the new options object
@imaTik0 imaTik0 force-pushed the feat/wasm-worker-count branch from 07476a1 to 9c390b0 Compare April 23, 2026 14:44
@imaTik0 imaTik0 requested a review from zurekz April 24, 2026 07:27
Comment thread async-engine/src/AsyncEngine.cpp Outdated
AsyncEngine::AsyncEngine() {
_pool = std::make_unique<WorkerPool>(4);
int requested = readWorkerCountFromJs();
size_t numWorkers = (requested >= 2) ? static_cast<size_t>(requested) : 4;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add constants for given values like:
WORKERS_MIN_REQUIRED_COUNT: 2
WORKERS_DEFAULT_COUNT: 4

Comment thread src/service/EndpointFactory.ts Outdated
// worker thread), before the main thread gets control back.
if (workerCount !== undefined) {
(window as unknown as Record<string, unknown>).__privmxWorkerCount = Math.max(
2,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add constants for given values like:
WORKERS_MIN_REQUIRED_COUNT: 2

@zurekz zurekz merged commit 862641a into devel Apr 24, 2026
1 check passed
@zurekz zurekz deleted the feat/wasm-worker-count branch April 24, 2026 11:40
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.

2 participants