grafana / loki

Like Prometheus, but for logs.
https://grafana.com/loki
GNU Affero General Public License v3.0
22.73k stars 3.31k forks source link

perf(mempool): Replace `sync.Mutex` with `sync.Once` #13293

Closed chaudum closed 1 week ago

chaudum commented 1 week ago

What this PR does / why we need it:

sync.Once uses an atomic integer as gate instead of a Mutex.

goos: linux
goarch: amd64
pkg: github.com/grafana/loki/v3/pkg/util/mempool
cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
             │  bench.old  │             bench.new              │
             │   sec/op    │   sec/op     vs base               │
Slab/1KB-8     138.5n ± 2%   125.1n ± 2%  -9.71% (p=0.000 n=10)
Slab/1MB-8     140.5n ± 3%   128.1n ± 2%  -8.83% (p=0.000 n=10)
Slab/128MB-8   143.0n ± 3%   130.4n ± 3%  -8.81% (p=0.000 n=10)
geomean        140.7n        127.8n       -9.12%

Checklist