-
Notifications
You must be signed in to change notification settings - Fork 376
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
feat: improve performance of getMetricAsPrometheusString #542
feat: improve performance of getMetricAsPrometheusString #542
Conversation
Thanks! Do you have any benchmarks before/after? https://github.com/siimon/prom-client/tree/master/benchmarks |
This change primarily impacts the performance of metrics that have a large number of rows in the Prometheus metrics output, e.g. histograms with several labels. In our application I saw metric generation time reduced by ~50%. This is not surprising since the number of times string values are copied as result of concatination is the same order as the number of rows. In the benchmark test I got 50% faster and 50% "acceptably slower". Every once in a while I would get one entry or another as slower, but it was inconsistent. |
Cool, thanks! |
Is this still an issue? Do you need me to do anything? |
If it's not too much trouble, a PR against |
Created a pr for |
Use Array.prototype.join instead string concatenation for constructing Prometheus metric string. This results in improved performance and reduced memory consumption, especially when there's a large amount of dimensions (labels and label values). In addition uses array iteration methods instead of explicit loops.