DataDog / datadog-go

go dogstatsd client library for datadog
MIT License
353 stars 132 forks source link

Optimistic metric allocation #308

Open opsengine opened 5 months ago

opsengine commented 5 months ago

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.