Skip to content

fix: Reduce allocations for classic histogram buckets #2081

Open
jaydeluca wants to merge 9 commits intomainfrom
reduce-allocations
Open

fix: Reduce allocations for classic histogram buckets #2081
jaydeluca wants to merge 9 commits intomainfrom
reduce-allocations

Conversation

@jaydeluca
Copy link
Copy Markdown
Collaborator

@jaydeluca jaydeluca commented Apr 30, 2026

Related to #2075

This reduces allocation and GC pressure in histogram text formatting by eliminating unnecessary intermediate allocations.

@jaydeluca jaydeluca changed the title Reduce allocations for classic histogram buckets feat: Reduce allocations for classic histogram buckets Apr 30, 2026
@jaydeluca jaydeluca changed the title feat: Reduce allocations for classic histogram buckets fix: Reduce allocations for classic histogram buckets Apr 30, 2026
@jaydeluca jaydeluca force-pushed the reduce-allocations branch from 4dbb3cc to 8ad2736 Compare April 30, 2026 21:18
jaydeluca added 4 commits May 1, 2026 16:37
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
@jaydeluca jaydeluca force-pushed the reduce-allocations branch from 494d653 to 5fe88b1 Compare May 1, 2026 20:37
jaydeluca added 3 commits May 2, 2026 11:32
Signed-off-by: Ubuntu <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in TextFormatUtil and 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.

Comment thread mise.toml
jaydeluca added 2 commits May 4, 2026 13:22
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
@jaydeluca jaydeluca marked this pull request as ready for review May 5, 2026 14:31
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.

2 participants