fix: Reduce allocations for classic histogram buckets #2081
Open
fix: Reduce allocations for classic histogram buckets #2081
Conversation
4dbb3cc to
8ad2736
Compare
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
494d653 to
5fe88b1
Compare
Signed-off-by: Ubuntu <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets allocation reduction in the text exposition layer by removing repeated string building in hot formatting paths and replacing Long.toString(...) calls with direct writer-based long formatting. It also adds benchmark coverage around histogram text rendering so the impact can be measured in the benchmarking module.
Changes:
- Added a manual
writeLong(...)helper inTextFormatUtiland reused it for counts and timestamps. - Cached base/suffixed metric names in the Prometheus, OpenMetrics, and OpenMetrics 2 text writers to avoid repeated concatenation in loops.
- Added a histogram text-format JMH benchmark and updated benchmark tasks to run with the GC profiler.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java |
Replaces Long.toString(...) with manual long/timestamp writing helpers. |
prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusTextFormatWriter.java |
Caches metric names and suffixed variants to reduce per-datapoint allocations in Prometheus text output. |
prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/OpenMetricsTextFormatWriter.java |
Applies the same cached-name optimization to OpenMetrics 1 text output. |
prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/OpenMetrics2TextFormatWriter.java |
Reduces classic histogram bucket-name concatenation in OpenMetrics 2 text output. |
mise.toml |
Updates benchmark tasks to pass JMH GC-profiler arguments. |
benchmarks/src/main/java/io/prometheus/metrics/benchmarks/HistogramTextFormatBenchmark.java |
Adds a dedicated JMH benchmark for classic histogram text rendering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #2075
This reduces allocation and GC pressure in histogram text formatting by eliminating unnecessary intermediate allocations.