feat(core): configurable WASM worker thread count via EndpointFactory setup()#161
Merged
Conversation
….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
07476a1 to
9c390b0
Compare
zurekz
requested changes
Apr 24, 2026
| AsyncEngine::AsyncEngine() { | ||
| _pool = std::make_unique<WorkerPool>(4); | ||
| int requested = readWorkerCountFromJs(); | ||
| size_t numWorkers = (requested >= 2) ? static_cast<size_t>(requested) : 4; |
Member
There was a problem hiding this comment.
Add constants for given values like:
WORKERS_MIN_REQUIRED_COUNT: 2
WORKERS_DEFAULT_COUNT: 4
| // worker thread), before the main thread gets control back. | ||
| if (workerCount !== undefined) { | ||
| (window as unknown as Record<string, unknown>).__privmxWorkerCount = Math.max( | ||
| 2, |
Member
There was a problem hiding this comment.
Add constants for given values like:
WORKERS_MIN_REQUIRED_COUNT: 2
added 2 commits
April 24, 2026 10:53
zurekz
approved these changes
Apr 24, 2026
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.
AsyncEngine (C++):
EndpointFactory (TypeScript):
Tests (E2E):