Observe the problem
Run the algorithm with 1 thread.
In a reference computer, this takes 6 seconds.
Then Run the algorithm with 8 threads.
On the same computer this takes 30 seconds.
The fix
The fix is convenient.
We use a parallel workload friendly allocator instead.
We keep the changes limited, only on the wasm bindings layer, as demonstrated on the right →
You may see the live demo of the fixed version here.
Enable wasm-allocator feature in wasm_bindings/Cargol.toml
orx-parallel = { version = "4.1",
features = ["wasm", "wasm-allocator"] }
Use parallel-friendly allocator in wasm_bindings/src/lib.rs
#[cfg(target_arch = "wasm32")]
#[global_allocator]
static GLOBAL_ALLOCATOR: orx_parallel::WasmParallelAllocator<32> =
orx_parallel::WasmParallelAllocator::new();