wgpu
wgpu copied to clipboard
Reduce string allocations related to labels and logging.
Description
Resource::label()is (occasionally, for destroyed resources specifically) called for logging, but always allocated aString, which would not necessarily be skipped by the logging macro (if the level filter is met, aformat_args!()is constructed even if it is skipped). Avoid that by making it return&strinstead.- This has one behavior change:
wgpu_core::command::CommandBufferwill return the"<CommandBuffer>"placeholder string instead of"". This avoids taking a lock in addition to the allocation, but it also meansRegistry::label_for_resource()won't produce a placeholder with ID. But if that behavior is desirable, surely it should be done more broadly (haveResource::labelreturn empty strings consistently), instead of only forCommandBuffer?
- This has one behavior change:
- Also avoid allocating a throwaway
Stringwhen creating an unlabeledCommandBuffer.
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 testto run tests. - [X] ~~Add change to
CHANGELOG.md. See simple instructions inside file.~~ Not worth mentioning.