Skip to content

attribute: avoid reflection for small fixed-array slice types in hashKV#8203

Closed
alliasgher wants to merge 3 commits intoopen-telemetry:mainfrom
alliasgher:perf-hash-slice-types
Closed

attribute: avoid reflection for small fixed-array slice types in hashKV#8203
alliasgher wants to merge 3 commits intoopen-telemetry:mainfrom
alliasgher:perf-hash-slice-types

Conversation

@alliasgher
Copy link
Copy Markdown
Contributor

Fixes #8200.

Applies the same type-switch fast path used for SLICE in #8166 to the four existing slice types: BOOLSLICE, INT64SLICE, FLOAT64SLICE, and STRINGSLICE.

The slice values for len 0-3 are stored as [N]T fixed arrays by SliceValue. Type-asserting directly on those avoids all reflection overhead for the most common lengths. Longer slices fall through to the existing reflect.ValueOf path unchanged.

Benchmarks

BenchmarkHashKVsSlices exercises only slice-type attributes (len 2-3, which hit the fixed-array fast path):

BenchmarkHashKVsSlices-10    ~99 ns/op    0 B/op    0 allocs/op

Micro-benchmark of the per-element path for [2]bool:

old (reflect): ~7 ns/op
new (type switch): ~1 ns/op   (~5.7x faster)

The overall BenchmarkHashKVs is unchanged since it includes many non-slice types, but the slice-specific path is significantly faster.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

attribute: Improve performance of hashValue for BOOLSLICE, INT64SLICE, FLOAT64SLICE, STRINGSLICE

2 participants