Reduce recordMetric allocations - #550
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #550 +/- ##
=======================================
- Coverage 85.6% 79.1% -6.6%
=======================================
Files 16 16
Lines 928 968 +40
=======================================
- Hits 795 766 -29
- Misses 107 145 +38
- Partials 26 57 +31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
boekkooi-impossiblecloud
force-pushed
the
record-metrics-tweaks
branch
from
October 20, 2025 12:59
cedbe4e to
0132836
Compare
boekkooi-impossiblecloud
force-pushed
the
record-metrics-tweaks
branch
from
October 20, 2025 13:16
0132836 to
66f0e2e
Compare
Contributor
Author
|
I rebased the PR as #549 was merged which cause estimatedAttributesOfGettersCount to become unused. |
Good day!
This PR improves the performance of the
recordMetricfunc by reducing the amount of allocations being done.Thanks for reviewing and maintaining the library and have a great day!
The result is the following
benchstatreport.Benchmarks where run using
go test -run '^$' -bench . -count 10Before (7ca8256)
``` goos: linux goarch: amd64 pkg: github.com/XSAM/otelsql cpu: AMD Ryzen 7 Pro 7735U with Radeon Graphics BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 3478968 388.2 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2576029 404.7 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2980551 425.8 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2988195 416.3 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2841171 430.5 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2625727 434.1 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2739985 432.3 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2739862 456.1 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2583672 460.2 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 2936508 433.2 ns/op 1248 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 916376 1330 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 967496 1329 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 843298 1370 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 946387 1272 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 970816 1585 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 938580 1336 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 990020 1302 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 859711 1358 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 952374 1301 ns/op 3808 B/op 7 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 891291 1460 ns/op 3808 B/op 7 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4768020 245.0 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4813402 267.0 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4592091 254.7 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4528048 270.0 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4833096 248.3 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4665340 276.3 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4903068 260.5 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4998130 269.5 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4446578 259.9 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4621431 270.4 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2277591 507.8 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2298198 540.1 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2350687 528.1 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2304780 531.4 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2445901 535.0 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2313202 501.3 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2361778 518.8 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2466976 505.9 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2155660 516.0 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2485371 518.6 ns/op 1848 B/op 9 allocs/op PASS ok github.com/XSAM/otelsql 61.655s ```After (eec0d05)
``` goos: linux goarch: amd64 pkg: github.com/XSAM/otelsql cpu: AMD Ryzen 7 Pro 7735U with Radeon Graphics BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 4389051 255.5 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 4510778 295.7 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 4080192 274.8 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 3928474 327.7 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 3772546 300.0 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 3317569 315.1 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 4186486 290.7 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 3900781 338.8 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 3985352 301.2 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/5-16 3302559 314.3 ns/op 864 B/op 4 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1345795 943.2 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1000000 1025 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1367355 948.7 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1214510 926.3 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1000000 1023 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1263034 887.6 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1000000 1095 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 999145 1002 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1272502 1001 ns/op 2464 B/op 5 allocs/op BenchmarkRecordMetric/InstrumentAttributesGetter/10-16 1330045 981.8 ns/op 2464 B/op 5 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4377711 269.4 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4913751 255.4 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4558237 262.3 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4593020 263.5 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4131170 257.7 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4871282 253.5 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4422524 279.8 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4552953 253.5 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4324983 262.9 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/5-16 4956482 257.1 ns/op 824 B/op 8 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2204943 545.3 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2431120 515.3 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2239924 497.3 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2321678 541.3 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2406284 487.6 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2315420 551.2 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2245003 503.1 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2214315 506.5 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2494950 524.0 ns/op 1848 B/op 9 allocs/op BenchmarkCreateSpan/AttributesGetter/10-16 2107402 497.8 ns/op 1848 B/op 9 allocs/op PASS ok github.com/XSAM/otelsql 65.040s ```