Skip to content

Reduce per-frame allocations: reuse emitter/order and reserve buffers in render state - #2

Merged
TiernanDeFranco merged 1 commit into
mainfrom
codex/locate-hot-path-allocations-for-optimization
May 7, 2026
Merged

Reduce per-frame allocations: reuse emitter/order and reserve buffers in render state#2
TiernanDeFranco merged 1 commit into
mainfrom
codex/locate-hot-path-allocations-for-optimization

Conversation

@TiernanDeFranco

Copy link
Copy Markdown
Collaborator

Motivation

  • Reduce frequent per-frame heap allocations and vector clears in particle preparation and render command draining to lower GC/allocator churn and improve runtime performance.

Description

  • Add an emitter_order: Vec<usize> field to GpuPointParticles3D and reuse it across frames instead of allocating a temporary emitter_order vector each prepare call.
  • Populate and sort self.emitter_order in prepare and iterate over it when pushing emitters, preserving capacity between frames.
  • Stop clearing the render resource scratch vector in Runtime::drain_render_commands so the pre-allocated scratch capacity can be reused by resource_api::drain_commands.
  • Add capacity reservations before Vec::append in RenderState::drain_commands and before appending pending transform roots in DirtyState::take_pending_transform_roots to avoid intermediate reallocations.

Testing

  • Built the workspace with cargo build to verify no compilation errors, and the build succeeded.
  • Ran the test suite with cargo test across affected crates to validate behavior, and the tests passed.

Codex Task

@TiernanDeFranco TiernanDeFranco added enhancement New feature or request and removed codex labels May 7, 2026
@TiernanDeFranco TiernanDeFranco self-assigned this May 7, 2026
@TiernanDeFranco
TiernanDeFranco merged commit 804d552 into main May 7, 2026
1 check passed
@TiernanDeFranco
TiernanDeFranco deleted the codex/locate-hot-path-allocations-for-optimization branch May 7, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant