Skip to content

Commit

Permalink
perf(chstorage): do not make an unnecessary copy of encoded attributes
Browse files Browse the repository at this point in the history
```
                │   old.txt    │              new.txt               │
                 │    sec/op    │   sec/op     vs base               │
_metricsBatch-32   1088.5µ ± 1%   992.1µ ± 1%  -8.86% (p=0.000 n=15)

                 │   old.txt    │               new.txt                │
                 │     B/op     │     B/op      vs base                │
_metricsBatch-32   290.8Ki ± 0%   156.4Ki ± 0%  -46.23% (p=0.000 n=15)

                 │   old.txt   │               new.txt               │
                 │  allocs/op  │  allocs/op   vs base                │
_metricsBatch-32   6.280k ± 0%   3.247k ± 0%  -48.30% (p=0.000 n=15)
```
  • Loading branch information
tdakkota committed Jan 18, 2024
1 parent 401f437 commit a3eb073
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/chstorage/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ClickHouse/ch-go/proto"
"github.com/go-faster/errors"
"github.com/go-faster/jx"
"go.opentelemetry.io/collector/pdata/pcommon"
"golang.org/x/exp/maps"

Expand Down Expand Up @@ -68,7 +69,13 @@ func (a *attributeCol) Append(v otelstorage.Attrs) {
if !ok {
idx = len(a.hashes)
a.hashes[h] = idx
a.index.Append(encodeAttributes(v.AsMap()))

e := jx.GetEncoder()
defer jx.PutEncoder(e)
encodeMap(e, v.AsMap())

// Append will copy passed bytes.
a.index.Append(e.Bytes())
}
a.col.AppendKey(idx)
}
Expand Down

0 comments on commit a3eb073

Please sign in to comment.