prometheus / prometheus/client_js
Speed up label escaping
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.5k
- Forks
- 429
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 22
Description
On the back of #798, there is now an opportunity to escape label values once at insert time rather than on every metrics call.
The metrics call is a high priority target for both time and space improvements. When I first came to the project, it was the most common complaint in the issue backlog. We have managed to speed up everything but this part. Collection is ~20% faster, aggregation 2.4x faster, but metrics are only a couple % faster.
With the introduction of #insert, we should be able to move the escapeString() call to insert. This could be done two ways:
- change the labels to only be escaped labels
- store the escaped form of the labels beside the original form
Number 2 may be more compatible, and since most strings do not need to be escaped in the first place, represent only a small increase in memory usage.
This work also may reduce or remove the need for the label cache in the Registry. Despite the use of a WeakMap for storage, this does represent a memory cost, and if the label concatenation is cheaper, then it's worth also considering whether the added overhead of the lookups is really worth the extra space and code, or whether the whole thing can be deleted.
Contributor guide
No contributing guide indexed for this repository
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 by reviewing #798 and the insertion path introduced there, then trace escapeString() and the Registry label cache. Compare storing escaped labels beside originals with replacing the stored labels, and measure the effect on metrics time, memory, and compatibility. Done means metrics performance improves without breaking label behavior and the cache decision is supported by measurements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- observability, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100