Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic metric allocation #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 as a code owner 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.

None yet

1 participant