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.
Allocate new metrics before the exclusive lock is acquired for
count()
andset()
. Theif
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.