@onimaxxing/worldgen 0.18.1 → 0.19.0

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,15 +42,21 @@ 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 `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.
45
+ * count; `'auto'` uses `navigator.hardwareConcurrency`.
46
+ *
47
+ * This used to be clamped to 4, because stock dlmalloc takes one
48
+ * global lock and worldgen's layout/mob phases are allocation-heavy,
49
+ * so extra workers serialized on malloc: on a 16-thread host,
50
+ * M-FLIP-C-42 peaked at 2 workers (1.52x) and then went BACKWARDS,
51
+ * reaching 0.67x at 16 — slower than not threading at all.
52
+ *
53
+ * The parallel build now installs a thread-caching allocator
54
+ * (`oni_wasm::alloc_cache`), and scaling is monotonic again, so the
55
+ * clamp is gone. Same coord/host, measured: 304 ms at 1 worker ->
56
+ * 164 at 2 -> 97 at 4 -> 68 at 8 -> 65 at 16 (4.74x). Speedup is now
57
+ * bounded by the cluster's world-size distribution, not the
58
+ * allocator — a 1-world coord still only reaches ~1.4x because just
59
+ * the in-world noise stage is parallel.
54
60
  * @returns {Promise<void>}
55
61
  */
56
62
  async function init(opts) {
@@ -70,12 +76,11 @@ async function init(opts) {
70
76
  }
71
77
 
72
78
  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).
79
+ // No clamp — the thread-caching allocator restored monotonic
80
+ // scaling; see the `threads` doc above for the measurements.
76
81
  const threads = typeof opts?.threads === 'number'
77
82
  ? opts.threads
78
- : Math.min(globalThis.navigator?.hardwareConcurrency ?? 4, 4);
83
+ : (globalThis.navigator?.hardwareConcurrency ?? 4);
79
84
  await mod.initThreadPool(threads);
80
85
  }
81
86
 
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.1",
5
+ "version": "0.19.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
Binary file
Binary file