@onimaxxing/worldgen 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +13 -2
- package/package.json +1 -1
- package/parallel/oni_wasm_bg.wasm +0 -0
- package/serial/oni_wasm_bg.wasm +0 -0
package/index.js
CHANGED
|
@@ -42,7 +42,15 @@ function _requireInit(method) {
|
|
|
42
42
|
* passed through to wasm-bindgen's init.
|
|
43
43
|
* @param {number | 'auto' | 'serial'} [opts.threads='auto'] `'serial'`
|
|
44
44
|
* forces the serial build; a number sets an explicit rayon worker
|
|
45
|
-
* count; `'auto'` uses `navigator.hardwareConcurrency`.
|
|
45
|
+
* count; `'auto'` uses `min(navigator.hardwareConcurrency, 4)`.
|
|
46
|
+
* The clamp is deliberate: Rust's wasm allocator takes a single
|
|
47
|
+
* global lock, and worldgen's layout phase is allocation-heavy, so
|
|
48
|
+
* many workers generating multiple worlds concurrently serialize on
|
|
49
|
+
* malloc and can erase the parallel win entirely (browser A/B on a
|
|
50
|
+
* 16-thread host: 8-world cluster 380 ms at 16 workers ≈ serial;
|
|
51
|
+
* ~330 ms at 4; ~285 ms at 2 — while a 1-world coord runs best at
|
|
52
|
+
* high counts, ~157 vs ~170 ms). 4 is the compromise that wins on
|
|
53
|
+
* both shapes; pass an explicit number to override.
|
|
46
54
|
* @returns {Promise<void>}
|
|
47
55
|
*/
|
|
48
56
|
async function init(opts) {
|
|
@@ -62,9 +70,12 @@ async function init(opts) {
|
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
if (wantParallel && typeof mod.initThreadPool === 'function') {
|
|
73
|
+
// Clamp 'auto' to 4 workers — see the `threads` doc above
|
|
74
|
+
// (allocator-lock contention makes high worker counts LOSE on
|
|
75
|
+
// multi-world clusters).
|
|
65
76
|
const threads = typeof opts?.threads === 'number'
|
|
66
77
|
? opts.threads
|
|
67
|
-
: (globalThis.navigator?.hardwareConcurrency ?? 4);
|
|
78
|
+
: Math.min(globalThis.navigator?.hardwareConcurrency ?? 4, 4);
|
|
68
79
|
await mod.initThreadPool(threads);
|
|
69
80
|
}
|
|
70
81
|
|
package/package.json
CHANGED
|
Binary file
|
package/serial/oni_wasm_bg.wasm
CHANGED
|
Binary file
|