You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(core): configurable WASM worker thread count via EndpointFactory setup() (#161)
* feat(core): configurable WASM worker thread count via EndpointFactory.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
* fix/post-review-fixes
* fix: clang-format fix
---------
Co-authored-by: Paweł Aniszewski <paniszewski@simplito.com>
Copy file name to clipboardExpand all lines: src/service/EndpointFactory.ts
+29-2Lines changed: 29 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -34,28 +34,55 @@ import { StreamApi } from "./StreamApi";
34
34
import{ThreadApi}from"./ThreadApi";
35
35
import{setGlobalEmCrypto}from"../crypto/index";
36
36
37
+
37
38
/**
38
39
* //doc-gen:ignore
39
40
*/
40
41
declarefunctionendpointWasmModule(): Promise<any>;// Provided by emscripten js glue code
41
42
43
+
exportinterfaceEndpointSetupOptions{
44
+
assetsBasePath?: string;
45
+
workerCount?: number;
46
+
}
47
+
42
48
/**
43
49
* Contains static factory methods - generators for Connection and APIs.
44
50
*/
45
51
exportclassEndpointFactory{
52
+
53
+
privatestaticreadonlyWORKER_COUNT_MIN=2;
54
+
46
55
privatestaticapi: Api;
47
56
privatestaticeventQueueInstance: EventQueue;
48
57
privatestaticassetsBasePath: string;
49
58
50
59
/**
51
60
* Load the Endpoint's WASM assets and initialize the Endpoint library.
52
61
*
53
-
* @param {string} [assetsBasePath] base path/url to the Endpoint's WebAssembly assets (like: endpoint-wasm-module.js, driver-web-context.js and others)
62
+
* @param {string | EndpointSetupOptions} [options] either a base path string (legacy) or an options object
63
+
* @param {string} [options.assetsBasePath] base path/url to the Endpoint's WebAssembly assets
64
+
* @param {number} [options.workerCount] number of async-engine worker threads (default: 4, minimum: 2)
0 commit comments