Skip to content

Conversation

avendel
Copy link

@avendel avendel commented Nov 2, 2024

One of the WithLabels overloads uses a params argument. Calling a method with a single value for a params argument allocates memory, and I suspect that using a single label is quite common.

This change will prevent that for the common scenario of having only one label, by introducing a non-allocating method.

Benchmark results

| Method                                   | Mean       | Error   | StdDev  | Allocated |
|----------------------------------------- |-----------:|--------:|--------:|----------:|
| WithLabels_OneMetric_ManySeries_OneLabel | 1,046.9 ns | 4.94 ns | 4.12 ns |     320 B |
| WithLabel_OneMetric_ManySeries_OneLabel  |   984.5 ns | 5.13 ns | 4.80 ns |         - |

Calling a method with a single value for a params argument allocates memory.

This change will prevent that for the common scenario of having only one label,
by introducing a non-allocating method.
@avendel avendel force-pushed the perf-single-label-value branch from c0e3895 to 24f72c3 Compare November 3, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant