@onimaxxing/worldgen 0.18.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 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
@@ -2,7 +2,7 @@
2
2
  "name": "@onimaxxing/worldgen",
3
3
  "type": "module",
4
4
  "description": "WASM entry point for ONI worldgen",
5
- "version": "0.18.0",
5
+ "version": "0.18.1",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
Binary file
Binary file