Repository navigation
Description
Summary
Replace Typhon's per-entity storage model with a batched architecture where N entities of the same archetype are packed together in SoA layout within a contiguous memory region. This eliminates the two dominant per-entity costs — hash map lookup (23%) and page fetch indirection (43%) — while preserving ACID transactions, MVCC, selective queries, and all three storage modes.
Design document: claude/design/Ecs/EntityClusters/ (11 documents)
Research: claude/scratch/cluster-architecture-research.md
Motivation
Profiling at 100K entities shows per-entity access costs 134 ns, of which only 20% is actual computation. The rest is overhead: EntityMap hash lookup (31 ns), component page fetches (58 ns), and metadata resolution (18 ns). Clusters eliminate this overhead by co-locating all component data for N entities in a single contiguous page region.
Expected Impact
| Metric | Current | Cluster (projected) |
|---|---|---|
| Bulk iteration (100K) | 13.4 ms | ~1.3 ms (10x) |
| Random entity access | 107 ns | ~77 ns (1.4x) |
| SV write (no index) | 110 ns | ~3 ns (37x) |
| Versioned HEAD read | 130-210 ns | ~13 ns (10-16x) |
| Spawn (single, no index) | 410 ns | ~114 ns (3.6x) |
| Working set (100K) | 19.2 MB (L3) | ~2.5 MB (L2) |
Key Design Decisions
- Cluster size: Auto-computed per archetype to maximize entities/page (N in [8..64])
- B+Trees: Per-archetype (not shared per ComponentTable)
- Zone maps: Per indexed field, lazy maintenance at tick fence, O(n/N) scan
- Query: Dual-path planner — Path A (B+Tree, selective) / Path B (zone map + SIMD, broad)
- Versioned: HEAD in cluster, revision chain separate
- Single storage path: No dual-mode fallback, variable N fits all archetypes
Implementation Phases
- Entity Clusters Phase 1: Core Cluster Storage #215 — Phase 1: Core Cluster Storage (SV only, no indexes)
- Entity Clusters Phase 2: Dirty Tracking & Tick Fence #216 — Phase 2: Dirty Tracking & Tick Fence (WAL, shadow buffers)
- Entity Clusters Phase 3a: B+Tree Index Integration & Zone Maps #217 — Phase 3a: B+Tree Index Integration & Zone Maps
- Entity Clusters Phase 3b: Spatial R-Tree Integration #220 — Phase 3b: Spatial R-Tree Integration (Dynamic)
- Entity Clusters Phase 3c: Static Spatial R-Tree Support #222 — Phase 3c: Static Spatial R-Tree Support (S)
- Entity Clusters Phase 4: Query & Parallel Dispatch #218 — Phase 4a: Query & Parallel Dispatch (zone map pruning, dual-path planner, cluster dispatch, views)
- Entity Clusters Phase 4b: SIMD Evaluation, K-way Merge & AntHill Migration #223 — Phase 4b: SIMD Evaluation, K-way Merge & AntHill Migration
- Entity Clusters Phase 5: Versioned Overlay #219 — Phase 5: Versioned Overlay (HEAD in cluster, chain separate)
- Entity Clusters Phase 6: Transient Component Cluster Support #225 — Phase 6: Transient Component Cluster Support (dual-segment: PersistentStore + TransientStore)
Known Degradations
- Checkpoint I/O: ~1.6x more pages written (larger stride → more pages)
- Cross-archetype sorted queries (K>10): K-way merge overhead
- Highly selective queries (<100 results): Zone map scan floor cost (~19 µs at 100K)
- Schema evolution: ~Cx more expensive (rebuilds all clusters, offline operation)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
Entity Clusters: GPU-Inspired Batched Entity Storage (#214) (#227)