Skip to content

Performance improvement plan: Phases 2-3 #6

@jakeklassen

Description

@jakeklassen

Context

Phase 1 (Array + Map EntityCollection) was completed and landed significant iteration gains. Phases 2 and 3 remain.

Baseline → Phase 1 Results

Benchmark Baseline Phase 1 Change
packed_5 139,836 156,720 +12%
simple_iter 80,937 155,658 +92%
frag_iter 44,291 49,980 +13%
entity_cycle 7,556 3,970 -47%
add_remove 21,209 22,525 +6%

Phase 2: Query/Archetype Caching

  • Cache archetypes by component signature (sorted, stringified)
  • Return existing archetype if query already exists
  • Expected impact: reduced memory allocation, faster repeated queries

Phase 3: Micro-optimizations

  • Change component in entityentity[component] !== undefined ✅ Done
  • Replace .every() with manual loops in hot paths ✅ Done
  • Inline hot-path operations where possible
  • Avoid creating closures in frequently-called methods

Comparison with miniplex (after Phase 1)

Benchmark objecs miniplex Diff
packed_5 156,720 183,637 -15%
simple_iter 155,658 161,876 -4%
frag_iter 49,980 51,206 -2%
entity_cycle 3,970 2,247 +77% ✅
add_remove 22,525 2,092 +977% ✅

Notes

  • entity_cycle regressed 47% from baseline in Phase 1, but still 77% faster than miniplex (Map overhead for index tracking)
  • Validate all changes with macro benchmarks (10+ trials) before landing
  • Cannot sacrifice DX or type safety

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions