Skip to content

perf: cache allocations in render loop and optimize backpack grouping #34

Description

@rvoidex7

Description

The game loop and render loop currently trigger repeated memory allocations on every frame (hot paths):

  1. simulation.get_backpack(...) allocates a fresh vector vec![InventoryItem::default(); 50] every time it is called.
  2. group_backpack(...) runs with O(N²) complexity due to nested linear searches, and is called multiple times during render layout updates.
  3. The active player HashMap is reconstructed from scratch in main.rs on every tick.

Proposed Changes

  1. Optimize group_backpack to use a HashMap-based O(N) grouping algorithm.
  2. Reuse a pre-allocated buffer for get_backpack calls instead of allocating a fresh vector on every frame.
  3. Cache active player visual stats in main.rs to avoid rebuilding the HashMap from scratch on every tick.

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