prometheus / prometheus/client_java
Extra allocations in `*TextFormatWriter` because of Java 8 target
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 833
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 86
Description
See this line of code:
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- java
- Domain
- build-system, release
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100