Skip to content

Conversation

opsengine
Copy link

@opsengine opsengine commented Jun 2, 2024

Allocate new metrics before the exclusive lock is acquired for count() and set(). The if condition in the critical section is more likely to be false than true, so this change will reduce its length and mostly without making unnecessary allocations.

Note that this optimization is already present in gauge() but for some reason is missing in the other two functions.

The motivation for this change is datadog profiling revealing lock contention in this critical section while an application was under load.

@opsengine opsengine marked this pull request as ready for review June 3, 2024 18:41
@opsengine opsengine requested a review from a team June 3, 2024 18:41
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.

1 participant