Skip to content

enhancement: Cache active map lookup in RingCollisionSystem — O(n) per tick is too slow #104

@TheMeinerLP

Description

@TheMeinerLP

Description

`RingCollisionSystem.findActiveMap()` iterates over all entities every tick to find the entity holding `ActiveMapComponent`. With 8 players, this is 8 linear scans per tick (160/s). As entity count grows this becomes a performance bottleneck that will manifest in tick overruns.

Acceptance Criteria

  • The active map is cached in a field on `RingCollisionSystem` (or via a dedicated `ActiveMapCache` helper)
  • Cache is invalidated/updated on map transitions (when `ActiveMapComponent` changes)
  • `findActiveMap()` is no longer called inside the per-player tick loop
  • Micro-benchmark or comment documents the before/after complexity

Technical Details

  • Simplest fix: store the game entity reference at system initialization time; access its `ActiveMapComponent` directly
  • Or: introduce an `EntityManager.getSingleton(Class)` convenience method for single-entity components
  • Applies the same pattern fix to any other system doing per-tick entity scans for singleton components

Dependencies

  • Phase wiring must be complete (so the game entity exists when the system initializes)

Estimate

S

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions