Skip to content

Improve command-buffer bake efficiency and add inspect chain helper#1

Open
mqxf wants to merge 1 commit intomainfrom
codex/analyze-and-improve-code-implementation
Open

Improve command-buffer bake efficiency and add inspect chain helper#1
mqxf wants to merge 1 commit intomainfrom
codex/analyze-and-improve-code-implementation

Conversation

@mqxf
Copy link
Copy Markdown
Member

@mqxf mqxf commented Apr 20, 2026

Motivation

  • Reduce unnecessary allocations and unsafe mut-casting in command-buffer baking to make finish faster and safer.
  • Provide a small, useful chainable primitive so users can run side effects (logging/metrics/validation) inside command chains without breaking the chain.

Description

  • Replaced drain(..).collect() uses for extracting tasks/controllers with std::mem::take to avoid extra allocations and drains in TaskChain::chain_semaphores and TaskChain::get_controllers (src/command_buffers/buffer.rs).
  • Changed RawCommandBuffer::finish to take &mut self, removed the internal unsafe self-mutation, precomputed the final task capacity, and incrementally extend the output vector to avoid an extra intermediate collect step (src/command_buffers/buffer.rs).
  • Added a new extension trait Inspect<T> with a chainable method .inspect(...) that runs a side-effect taking &T and returns the original value unchanged, enabling non-intrusive inspection in command chains (src/command_buffers/commands.rs).
  • Minor formatting and ergonomic cleanups to signatures and whitespace (small refactors across buffer.rs/commands.rs).
  • Public command-buffer API unchanged; improvements are internal and additive.

Testing

  • Ran cargo test --all-features, which completed successfully (unit tests and doc-tests passed).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant