SyncMetricStorage guards every RecordLong/RecordDouble call with a single SpinLockMutex over the entire AttributesHashMap. When multiple threads share one instrument, all measurements serialize on this lock — including the heavy MetricAttributes construction from KeyValueIterable.
The BM_MeasurementsThreadsShareCounterTest benchmark confirms this: shared-counter throughput is significantly worse than per-thread counters.
The lock granularity could be improved.
References
SyncMetricStorageguards everyRecordLong/RecordDoublecall with a singleSpinLockMutexover the entireAttributesHashMap. When multiple threads share one instrument, all measurements serialize on this lock — including the heavyMetricAttributesconstruction fromKeyValueIterable.The
BM_MeasurementsThreadsShareCounterTestbenchmark confirms this: shared-counter throughput is significantly worse than per-thread counters.The lock granularity could be improved.
References
sync_metric_storage.hAttributesHashMap:attributes_hashmap.hSpinLockMutex:spin_lock_mutex.h