You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-27 22:49:15 +02:00
Performance improvements for attribute value AsStringSlice, AsFloat64Slice, AsInt64Slice, AsBoolSlice (#6011)
Good day,
This PR changes As[Bool|Int64|Float64|String]Slice to use a little less
reflection.
The benchstat result of this is as follows.
```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/internal/attribute
cpu: AMD Ryzen 7 Pro 7735U with Radeon Graphics
│ org.txt │ new.txt │
│ sec/op │ sec/op vs base │
AsFloat64Slice-16 373.3n ± 41% 181.0n ± 42% -51.51% (p=0.000 n=10)
│ org.txt │ new.txt │
│ B/op │ B/op vs base │
AsFloat64Slice-16 64.00 ± 0% 40.00 ± 0% -37.50% (p=0.000 n=10)
│ org.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
AsFloat64Slice-16 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10)
```
---------
Co-authored-by: Damien Mathieu <42@dmathieu.com>
This commit is contained in:
@@ -133,3 +133,13 @@ func BenchmarkStringSliceValue(b *testing.B) {
|
||||
sync = StringSliceValue(s)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAsFloat64Slice(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
var in interface{} = [2]float64{1, 2.3}
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
sync = AsFloat64Slice(in)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user