Skip to content

Swap gizmo storage and buffer to keep the allocation - #25549

Open
IceSentry wants to merge 2 commits into
bevyengine:mainfrom
IceSentry:gizmo_storage_swap
Open

Swap gizmo storage and buffer to keep the allocation#25549
IceSentry wants to merge 2 commits into
bevyengine:mainfrom
IceSentry:gizmo_storage_swap

Conversation

@IceSentry

Copy link
Copy Markdown
Contributor

Objective

  • When drawing gizmos from multiple systems, combining the buffers at the end of the frame can trigger a lot of new allocations

Solution

  • Instead of taking the buffer and creating a new one, swap with the existing buffer and clear the one that stays in the main world. This way the allocation is reused.
  • Technically, if someone spawns a lot of gizmos for a single frame then never spawns them again then the memory will never be cleared but I believe this isn't a common use case for gizmos but this is a tradeoff. If it becomes an issue we could check how the capacity vs len compares over a few frame and shrink it.

Testing

  • I added a new benchmark that measures the impact of this over multiple lines drawn and systems.
  • If you have a single system drawing a few lines then this new approach is marginally slower but in every other case it's faster.

Showcase

image

@IceSentry IceSentry added C-Performance A change motivated by improving speed, memory usage or compile times A-Gizmos Visual editor and debug gizmos S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Gizmos Visual editor and debug gizmos C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant