archetype-ecs 1.5.1 → 1.5.2

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.
Files changed (2) hide show
  1. package/README.md +13 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -256,7 +256,7 @@ Supports stripping components, skipping entities, and custom serializers.
256
256
 
257
257
  ### WASM SIMD
258
258
 
259
- archetype-ecs automatically detects WASM SIMD support and enables it when available. No configuration needed `createEntityManager()` does the right thing.
259
+ `fieldAdd` uses WASM SIMD to add fields in bulk 4x faster than a JS loop for float data:
260
260
 
261
261
  ```ts
262
262
  em.forEach([Position, Velocity], (arch) => {
@@ -265,14 +265,22 @@ em.forEach([Position, Velocity], (arch) => {
265
265
  })
266
266
  ```
267
267
 
268
- #### How auto-detection works
268
+ #### When does SIMD kick in?
269
269
 
270
- On first `createEntityManager()` call, the library tries to compile a small (500-byte) WebAssembly module that uses SIMD instructions. If compilation succeeds, the runtime supports SIMD and WASM mode is enabled. The compiled module is cached — subsequent calls reuse it with zero overhead. If compilation fails (e.g. older browser, restricted environment), it falls back to plain JS. You can check or override this:
270
+ All three conditions must be true:
271
+
272
+ | Condition | Check | Fallback |
273
+ |---|---|---|
274
+ | Runtime supports WASM SIMD | Tested once at startup by compiling a 500-byte SIMD module | All storage and iteration stays in plain JS |
275
+ | WASM mode not disabled | `createEntityManager()` (default) or `{ wasm: true }` | `createEntityManager({ wasm: false })` forces JS-only |
276
+ | Field type is `f32` | `fieldAdd` checks if both arrays are `Float32Array` | Scalar JS loop `dst[i] += src[i]` |
277
+
278
+ WASM SIMD is supported in all modern browsers (Chrome 91+, Firefox 89+, Safari 16.4+) and Node.js 16+.
271
279
 
272
280
  ```ts
273
281
  import { isWasmSimdAvailable } from 'archetype-ecs'
274
282
 
275
- isWasmSimdAvailable() // true if SIMD is supported
283
+ isWasmSimdAvailable() // true if runtime supports SIMD
276
284
  createEntityManager({ wasm: false }) // force JS-only mode
277
285
  ```
278
286
 
@@ -282,15 +290,11 @@ Regular JavaScript processes one float at a time. When you write `px[i] += vx[i]
282
290
 
283
291
  WASM SIMD uses `f32x4.add`: a single CPU instruction that adds **4 floats in parallel**, directly in 32-bit precision. For 1M entities, that's 250K instructions instead of 1M, with no conversion overhead.
284
292
 
285
- `fieldAdd(target, source)` dispatches to this SIMD kernel for `Float32Array` fields and falls back to a scalar loop for other types. Your code stays the same either way.
286
-
287
293
  #### Storage layout
288
294
 
289
- When WASM mode is active, all numeric TypedArrays (`Float32Array`, `Int32Array`, etc.) are allocated on a shared `WebAssembly.Memory` via a bump allocator. This means the SIMD kernel can operate directly on the data without copying. String fields always use regular JS arrays.
295
+ When WASM mode is active, all numeric TypedArrays (`Float32Array`, `Int32Array`, etc.) are allocated on a shared `WebAssembly.Memory` via a bump allocator. This means the SIMD kernel operates directly on the data no copying between JS and WASM. String fields always use regular JS arrays.
290
296
 
291
- **Details:**
292
297
  - The arena reserves 128 MB virtual address space (lazily committed — no physical RAM cost on most OSes)
293
- - `fieldAdd` uses SIMD for `Float32Array` fields; other types fall back to scalar
294
298
  - The bump allocator doesn't reclaim memory — frequent archetype churn may waste space
295
299
 
296
300
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archetype-ecs",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Lightweight archetype-based Entity Component System",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",