promql: avoid unnecessary Metric.Get() calls in functions.go#17676
Conversation
Signed-off-by: Vilius Pranckaitis <vpranckaitis@gmail.com>
|
Please show benchmark results, as requested in the PR template. |
bboreham
left a comment
There was a problem hiding this comment.
Thanks for this; I think it's a good idea.
I would rather defer evaluation as far as possible, e.g. into histogramRate, and add a small helper function to shorten the code where used. Then don't create a new variable metricName anywhere it would only be used once.
Did not write a separate benchmark, but used the exisitng The benchmark results show 1–6% reduction in runtime, and practically no change in allocations. |
@bboreham I've refactored the code to use Also, pushed the metric name extraction further down into |
Moved some
Metric.Get()calls in PromQL functions to avoid unnecessary label extraction. Withstringlabelsthat is a non-trivial amount of work, as shown by CPU profiles. In many cases, this work was done to extract metric name, and was only used if annotations were emitted.In the same go I also replaced
labels.MetricNamewithmodel.MetricNameLabel, since the former was deprecated.Which issue(s) does the PR fix:
Does this PR introduce a user-facing change?