Skip to content

Commit 4aebfc9

Browse files
committed
perf: avoid unnecessary llTailBatch
1 parent b8175b2 commit 4aebfc9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cache.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,11 @@ func NewFlattenCache(limit int) CacheStore {
249249
f.lrup = sync.Pool{New: func() any {
250250
b := &lrBatch{m: make(map[*flatentry]struct{}, lrBatchSize)}
251251
runtime.SetFinalizer(b, func(b *lrBatch) {
252-
f.mu.Lock()
253-
f.llTailBatch(b)
254-
f.mu.Unlock()
252+
if len(b.m) >= 0 {
253+
f.mu.Lock()
254+
f.llTailBatch(b)
255+
f.mu.Unlock()
256+
}
255257
})
256258
return b
257259
}}
@@ -312,7 +314,7 @@ func (f *flatten) Flight(key, cmd string, ttl time.Duration, now time.Time) (Red
312314
if v, _ := e.find(cmd, ts); v != nil {
313315
batch := f.lrup.Get().(*lrBatch)
314316
batch.m[e] = struct{}{}
315-
if len(batch.m) == lrBatchSize {
317+
if len(batch.m) >= lrBatchSize {
316318
f.mu.Lock()
317319
f.llTailBatch(batch)
318320
f.mu.Unlock()

0 commit comments

Comments
 (0)