Commit fbce18a
perf(fetch): avoid allocations in client_scope for borrowed-'static names (#514)
`client_scope` previously called `to_string()` on the runtime and
transport names, forcing a heap allocation on every client build even
though the transport already stores these names as `Cow<'static, str>`.
`client_scope` now takes `impl Into<Value>` for the runtime and
transport names — the exact bound `KeyValue::new` requires — and hands
each value straight into the instrumentation scope attributes with no
extra clone inside the function. The production call sites in
`client_builder.rs` pass
`transport.runtime().clone()`/`transport.name().clone()`; cloning the
transport's `Cow<'static, str>` is allocation-free for the common
borrowed-`'static` case and simply hands over ownership. The in-file
unit tests pass plain `&'static str` literals, which likewise convert
into `Value` without allocating.
Net effect: borrowed-`'static` runtime/transport names no longer
allocate when building the meter scope, and the signature stays
idiomatic (no `clippy::ptr_arg` `#[expect]` or `&Cow` borrow needed).
Verified with `just package=fetch clippy` (clean) and `just
package=fetch test` (153 passed).
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 828ced2 commit fbce18a
2 files changed
Lines changed: 8 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
245 | 248 | | |
246 | 249 | | |
247 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
| 104 | + | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
0 commit comments