Extra allocations in `*TextFormatWriter` because of Java 8 target

Open
#2,075 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Tech stack
java

Research direction

Start with OpenMetricsTextFormatWriter.java at the linked line and review how the project targets Java 8. Then investigate the artifact-publishing and multi-release JAR options described in the issue. Done would be a documented, maintainer-approved approach for reducing these allocations across the relevant TextFormatWriter code.

Written by the indexing model from the issue text.

Description

See this line of code:

https://github.com/prometheus/client_java/blob/fa68aa7789c53d54ea1783f120194a3feae7e7b8/prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/OpenMetricsTextFormatWriter.java#L412

Because of the Java 8 target, the string concatenation gets compiled to something like new StringBuilder().append(name).append(suffix).toString(), which allocates the memory at least twice (for the buffer in the StringBuilder and for the resulting string).

If the code was compiled for at least Java 9, it would use StringConcatFactory, which in this case would allocate the memory only for the resulting string.

Would the maintainers consider publishing multiple artifacts for different Java targets, or using multi-release JARs for the purpose of this and similar optimizations?

Dominant language
Java
Stars
2.3k
Forks
833
Avg merge
2d 16h
Merged PRs (30d)
86

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prometheus/client_java

All issues in prometheus/client_java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.