Skip to content

Commit

Permalink
perf(otelstorage): increase Attrs on-stack sorting threshold
Browse files Browse the repository at this point in the history
```
cpu: AMD Ryzen 9 5950X 16-Core Processor
                  │   old.txt   │            new.txt            │
                  │   sec/op    │   sec/op     vs base          │
InserterTraces-32   557.1µ ± 1%   553.5µ ± 1%  ~ (p=0.081 n=15)

                  │   old.txt    │               new.txt                │
                  │     B/op     │     B/op      vs base                │
InserterTraces-32   56.02Ki ± 0%   28.29Ki ± 0%  -49.50% (p=0.000 n=15)

                  │   old.txt   │              new.txt              │
                  │  allocs/op  │ allocs/op   vs base               │
InserterTraces-32   1009.0 ± 0%   969.0 ± 0%  -3.96% (p=0.000 n=15)
```
  • Loading branch information
tdakkota committed Jul 19, 2024
1 parent a18c67c commit a249e32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/chstorage/attributes_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ func encodeMap(e *jx.Encoder, m pcommon.Map, additional ...[2]string) {
value value
}
var pairs []pair
if l := m.Len(); l < 16 {
pairs = make([]pair, 0, 16)

const stackThreshold = otelstorage.MapStackThreshold
if l := m.Len(); l < stackThreshold {
pairs = make([]pair, 0, stackThreshold)
} else {
pairs = make([]pair, 0, m.Len()+len(additional))
}
Expand Down
7 changes: 5 additions & 2 deletions internal/otelstorage/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func (h Hash) String() string {
return hex.EncodeToString(h[:])
}

// MapStackThreshold defines common constant for on-stack [Attrs] sorting.
const MapStackThreshold = 32

// AttrHash computes attributes hash.
func AttrHash(m pcommon.Map) Hash {
h := xxh3.New()
Expand Down Expand Up @@ -74,8 +77,8 @@ func hashMap(h *xxh3.Hasher, m pcommon.Map) {
value pcommon.Value
}
var pairs []pair
if l := m.Len(); l < 16 {
pairs = make([]pair, 0, 16)
if l := m.Len(); l < MapStackThreshold {
pairs = make([]pair, 0, MapStackThreshold)
} else {
pairs = make([]pair, 0, m.Len())
}
Expand Down

0 comments on commit a249e32

Please sign in to comment.