Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pkg/util/mempool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
type slab struct {
buffer chan unsafe.Pointer
size, count int
mtx sync.Mutex
once sync.Once
metrics *metrics
name string
}
Expand Down Expand Up @@ -49,11 +49,7 @@ func (s *slab) init() {

func (s *slab) get(size int) ([]byte, error) {
s.metrics.accesses.WithLabelValues(s.name, opTypeGet).Inc()
s.mtx.Lock()
if s.buffer == nil {
s.init()
}
defer s.mtx.Unlock()
s.once.Do(s.init)

// wait for available buffer on channel
var buf []byte
Expand Down
1 change: 0 additions & 1 deletion pkg/util/mempool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func BenchmarkSlab(b *testing.B) {
} {
b.Run(flagext.ByteSize(uint64(sz)).String(), func(b *testing.B) {
slab := newSlab(sz, 1, newMetrics(nil, "test"))
slab.init()
b.ResetTimer()

for i := 0; i < b.N; i++ {
Expand Down
Loading