Optimize the new inhibitor implementation for ~2.5x performance improvement #4668
Merged
SuperQ merged 3 commits intoprometheus:mainfrom Nov 1, 2025
Merged
Conversation
Signed-off-by: Ethan Hunter <ehunter@hudson-trading.com>
Signed-off-by: Ethan Hunter <ehunter@hudson-trading.com>
bdfb74b to
f487c04
Compare
Contributor
Author
siavashs
requested changes
Oct 30, 2025
Contributor
siavashs
left a comment
There was a problem hiding this comment.
Minor issue, otherwise LGTM 👍
siavashs
reviewed
Oct 30, 2025
Co-authored-by: Siavash Safi <git@hosted.run> Signed-off-by: Ethan Hunter <fc.spaceman@gmail.com>
siavashs
approved these changes
Oct 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#4607 massively improved inhibitor performance, but had some regressions compared to #4134. This PR is the result of an optimization pass where I tried to get back some of the performance.
These changes were mostly guided by profiling and come in two categories:
Withon prometheus metric vectors. These require allocating a map, hashing each key, and then a somewhat expensive call toWithitself. I was able to move these into the one-time construction of the inhibitor metrics.time.Now(). First, use the time taken at the beginning ofMutesasnowfor all inhibit rule evaluations. This reduces calls totime.Now()and makes inhibitor behavior a little more consistent (since alerts can't resolve mid-execution anymore). Second, calculatetime.Now()once for the two metrics that track inhibitor performance when an inhibition is found. Each call totime.Sincecallstime.Now.Overall, this leads to reasonable performance gains:
mainvs. this PR:Optimization (1) vs (1) and (2)
This PR vs #4134
In summary: This PR is a fair bit faster than what's on
main, but it's still ~3x slower than #4134 in the bechmark suite. This is mostly caused by a much higher per-inhibition rule cost. I don't think we can significantly reduce that without removing some of the new metrics (which probably isn't worth it), but there might be something more I can find.