Skip to content

2.4x improvement in Cluster aggregation performance - #692

Merged
jdmarshall merged 8 commits into
prometheus:mainfrom
jdmarshall:clusterLabels
Jun 26, 2026
Merged

2.4x improvement in Cluster aggregation performance#692
jdmarshall merged 8 commits into
prometheus:mainfrom
jdmarshall:clusterLabels

Conversation

@jdmarshall

@jdmarshall jdmarshall commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

Use a similar strategy to LabelMap for stats coalescing for cluster.js

This has to wrestle with the problem of lack of fore-knowledge of the
canonical set of labels. We achieve this by assuming 6 labels to
begin with, first filling in the empties as we discover new ones, and
tnen expanding the columns by ⌈25%⌉ if they don't, and re-keying the
entire table (by concatenating extra ||'s onto the end)..

cluster ⇒ aggregate()

Summary (vs. baseline):
 ⇒ prom-client@latest            | ██████████─────────────── | 4.18 ops/sec | 11 samples (baseline)
 ⇒ prom-client@trunk             | ██████████▌────────────── | 4.26 ops/sec | 11 samples (1.02x faster)
 ⇒ prom-client@current           | █████████████████████████ | 10 ops/sec | 11 samples (2.40x faster)

@jdmarshall jdmarshall changed the title Cluster labels 2.5x improvement in Cluster aggregation performance Jul 29, 2025
@jdmarshall

jdmarshall commented Jul 29, 2025

Copy link
Copy Markdown
Contributor Author

This should fix #628

A lot of the gain here is that keyFrom is roughly 2x as fast as hashObject. But the shorter key also makes the Map a little faster, and the memory pressure a bit better.

@jdmarshall

Copy link
Copy Markdown
Contributor Author

Node 20 did not support Iterator.filter??

I'm surprised it's still in LTS. Working on it.

@jdmarshall jdmarshall changed the title 2.5x improvement in Cluster aggregation performance 2.4x improvement in Cluster aggregation performance Jul 29, 2025
@jdmarshall
jdmarshall force-pushed the clusterLabels branch 2 times, most recently from b3916cd to c37ed35 Compare November 3, 2025 23:48
@SimenB

SimenB commented Nov 27, 2025

Copy link
Copy Markdown
Collaborator

@jdmarshall sorry, missed this. Mind resolving the conflict? Your new benchmark runner has also landed 🙂

This also fixes issue with prettier.
This reverts most of commit 9251668.

Except for some of the tests.
This has to wrestle with the problem of lack of fore-knowledge of the
canonical set of labels. We achieve this by assuming 6 labels to
begin with, first filling in the empties as we discover new ones, and
tnen expanding the columns by ⌈25%⌉ if they don't, and re-keying the
entire table (by concatenating extra ||'s onto the end)..

Before and after:

✓ cluster ➭ aggregate() is 6.088% faster.
✓ cluster ➭ aggregate() is 149.4% faster.

@SimenB SimenB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks!

@SimenB

SimenB commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator
image

I'm not allowed to push to your fork to resolve the conflict 😅

@jdmarshall

Copy link
Copy Markdown
Contributor Author

fixed. For now

@jdmarshall

Copy link
Copy Markdown
Contributor Author

@SimenB can we land this?

@jdmarshall
jdmarshall merged commit 3301a4d into prometheus:main Jun 26, 2026
13 checks passed
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