The Physics of Memory (a.k.a. Can JavaScript ECS?)
A JavaScript benchmark shows ECS (Entity Component System) can outperform OOP in physics simulations by 5–10x due to better CPU cache usage from contiguous memory layouts, though performance gains depend on the specific workload.
Background
- **ECS (Entity-Component-System)** is a software pattern that organizes game/simulation logic around *entities* (IDs), *components* (plain data), and *systems* (code that processes components). It is often contrasted with **OOP** (objects bundling data + methods).
- The article benchmarks ECS-style code vs. OOP in JavaScript for physics simulations. The key claim: ECS can outperform OOP in JS by using **typed arrays** (e.g., `Float64Array`) and cache-friendly data layouts — even in a JIT-compiled, garbage-collected language.
- Author **David Murphy** is a game engine developer and open-source contributor, known for the `remq` ECS library and work on multiplayer/WebGL projects.
- This matters because ECS powers modern game engines (Unity DOTS, Bevy, Flecs), but its benefits are typically discussed for C++/Rust. Showing significant JS speedups challenges assumptions about the browser's viability for compute-heavy tasks like real-time physics.