wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Reduce string allocations related to labels and logging.

Open kpreid opened this issue 1 year ago • 0 comments

Description

  • Resource::label() is (occasionally, for destroyed resources specifically) called for logging, but always allocated a String, which would not necessarily be skipped by the logging macro (if the level filter is met, a format_args!() is constructed even if it is skipped). Avoid that by making it return &str instead.
    • This has one behavior change: wgpu_core::command::CommandBuffer will return the "<CommandBuffer>" placeholder string instead of "". This avoids taking a lock in addition to the allocation, but it also means Registry::label_for_resource() won't produce a placeholder with ID. But if that behavior is desirable, surely it should be done more broadly (have Resource::label return empty strings consistently), instead of only for CommandBuffer?
  • Also avoid allocating a throwaway String when creating an unlabeled CommandBuffer.

Testing

Ran cargo xtask test. All failures on my machine are unrelated to label strings as far as I know.

Checklist

  • [X] Run cargo fmt.
  • [X] Run cargo clippy. If applicable, add:
    • [ ] --target wasm32-unknown-unknown
    • [ ] --target wasm32-unknown-emscripten
  • [X] Run cargo xtask test to run tests.
  • [X] ~~Add change to CHANGELOG.md. See simple instructions inside file.~~ Not worth mentioning.

kpreid avatar May 11 '24 19:05 kpreid