Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid allocations for single label value #486

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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