Skip to content

Entity Clusters: GPU-Inspired Batched Entity Storage #214

Closed

Description

@nockawa

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

Known Degradations

  1. Checkpoint I/O: ~1.6x more pages written (larger stride → more pages)
  2. Cross-archetype sorted queries (K>10): K-way merge overhead
  3. Highly selective queries (<100 results): Zone map scan floor cost (~19 µs at 100K)
  4. Schema evolution: ~Cx more expensive (rebuilds all clusters, offline operation)

Activity

  1. moved this to In Progress in Typhon devon Apr 5, 2026
  2. moved this from In Progress to Done in Typhon devon Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions