Attribute cardinality limiting seems to account for a very small (~2ns) portion of the overhead.
Lookup based on the attribute set accounts for ~40ns of the overhead for the no-attributes case, and the vast majority of the overhead for the with-attributes case. OTel would need to introduce bound instruments to remove this chunk of overhead.
Our counter increment function (with locking) accounts for ~8ns of the overhead. We use a simple lock and increment a counter value. Prometheus appears to have implemented some optimizations for this. Benchmarks without any measurement whatsoever:
The remaining overhead is from the API, and from the Options pattern which requires calling NewAddConfig. This would presumably be eliminated if instruments were already bound to attributes.
Looking into https://github.com/open-telemetry/opentelemetry-go/issues/5542. Closing, as this is not meant to be merged.
My original local benchmark:
Exemplar collection accounts for ~50ns of the overhead (https://github.com/open-telemetry/opentelemetry-go/commit/a1bead9640dbcc045de3df8b1c6c05e1f08eba28), even though I believe we shouldn't be collecting exemplars by default, and we aren't doing tracing. This is probably a good area to optimize.
Attribute cardinality limiting seems to account for a very small (~2ns) portion of the overhead.
Lookup based on the attribute set accounts for ~40ns of the overhead for the no-attributes case, and the vast majority of the overhead for the with-attributes case. OTel would need to introduce bound instruments to remove this chunk of overhead.
Our counter increment function (with locking) accounts for ~8ns of the overhead. We use a simple lock and increment a counter value. Prometheus appears to have implemented some optimizations for this. Benchmarks without any measurement whatsoever:
The remaining overhead is from the API, and from the Options pattern which requires calling NewAddConfig. This would presumably be eliminated if instruments were already bound to attributes.