Skip to content

Commit 6c04ae0

Browse files
committed
triedb/pathdb: cache slice pointer
1 parent a26b05b commit 6c04ae0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

triedb/pathdb/lookup.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,26 @@ import (
2727
// slicePool is a shared pool of hash slice, for reducing the GC pressure.
2828
var slicePool = sync.Pool{
2929
New: func() interface{} {
30-
return make([]common.Hash, 0, 64) // Pre-allocate a slice with a reasonable capacity.
30+
slice := make([]common.Hash, 0, 16) // Pre-allocate a slice with a reasonable capacity.
31+
return &slice
3132
},
3233
}
3334

3435
// getSlice obtains the hash slice from the shared pool.
3536
func getSlice() []common.Hash {
36-
return slicePool.Get().([]common.Hash)
37+
slice := *slicePool.Get().(*[]common.Hash)
38+
slice = slice[:0]
39+
return slice
3740
}
3841

3942
// returnSlice returns the hash slice back to the shared pool for following usage.
4043
func returnSlice(slice []common.Hash) {
4144
// Discard the large slice for recycling
42-
if len(slice) > 1024 {
45+
if len(slice) > 128 {
4346
return
4447
}
4548
// Reset the slice before putting it back into the pool
46-
slicePool.Put(slice[:0])
49+
slicePool.Put(&slice)
4750
}
4851

4952
// lookup is an internal help structure to quickly identify

0 commit comments

Comments
 (0)