bevyengine / bevyengine/bevy

Optimize CommandQueue Allocation

Open
#20,733 0 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Feature C-Performance
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?
Right now, `CommandQueue` is built on top of a `Vec>` as an arbitrary heterogeneous byte buffer that is cleared on application, but never deallocated until the `CommandQueue` is dropped. This isn't the greatest allocation strategy as the entire Vec needs to be reallocated each time the capacity is exceeded, and the `CommandQueue` always keeps an allocation matching it's peak, not it's current or average usage.

## What solution would you like?
The append-only use of `CommandQueue` is very close to that of a bump allocator, and `bumpalo` is already in the `bevy_ecs` dependency tree. Either use `bumpalo` to allocate commands or create a similar allocation strategy. Drop all allocated chunks upon the queue being flushed.

This may also allow us to properly align all incoming commands to avoid unaligned reads in command implementations (avoiding the need for #20593).

## What alternative(s) have you considered?
Leave it as is. The approach used is already very efficient.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.