Skip to content

Commit 90218fd

Browse files
committed
triedb/pathdb: remove sync pool
1 parent 350a82c commit 90218fd

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

triedb/pathdb/lookup.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,6 @@ import (
2525
"golang.org/x/sync/errgroup"
2626
)
2727

28-
// slicePool is a shared pool of hash slice, for reducing the GC pressure.
29-
var slicePool = sync.Pool{
30-
New: func() interface{} {
31-
slice := make([]common.Hash, 0, 16) // Pre-allocate a slice with a reasonable capacity.
32-
return &slice
33-
},
34-
}
35-
36-
// getSlice obtains the hash slice from the shared pool.
37-
func getSlice() []common.Hash {
38-
slice := *slicePool.Get().(*[]common.Hash)
39-
slice = slice[:0]
40-
return slice
41-
}
42-
43-
// returnSlice returns the hash slice back to the shared pool for following usage.
44-
func returnSlice(slice []common.Hash) {
45-
slicePool.Put(&slice)
46-
}
47-
4828
// lookup is an internal structure used to efficiently determine the layer in
4929
// which a state entry resides.
5030
type lookup struct {
@@ -159,7 +139,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
159139
for accountHash := range diff.states.accountData {
160140
list, exists := l.accounts[accountHash]
161141
if !exists {
162-
list = getSlice()
142+
list = make([]common.Hash, 0, 16)
163143
}
164144
list = append(list, state)
165145
l.accounts[accountHash] = list
@@ -178,7 +158,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
178158
for slotHash := range slots {
179159
list, exists := subset[slotHash]
180160
if !exists {
181-
list = getSlice()
161+
list = make([]common.Hash, 0, 16)
182162
}
183163
list = append(list, state)
184164
subset[slotHash] = list
@@ -212,7 +192,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
212192
if i == 0 {
213193
list = list[1:]
214194
if cap(list) > 1024 {
215-
list = append(getSlice(), list...)
195+
list = append(make([]common.Hash, 0, len(list)), list...)
216196
}
217197
} else {
218198
list = append(list[:i], list[i+1:]...)
@@ -227,7 +207,6 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
227207
if len(list) != 0 {
228208
l.accounts[accountHash] = list
229209
} else {
230-
returnSlice(list)
231210
delete(l.accounts, accountHash)
232211
}
233212
}
@@ -252,7 +231,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
252231
if i == 0 {
253232
list = list[1:]
254233
if cap(list) > 1024 {
255-
list = append(getSlice(), list...)
234+
list = append(make([]common.Hash, 0, len(list)), list...)
256235
}
257236
} else {
258237
list = append(list[:i], list[i+1:]...)
@@ -267,7 +246,6 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
267246
if len(list) != 0 {
268247
subset[slotHash] = list
269248
} else {
270-
returnSlice(subset[slotHash])
271249
delete(subset, slotHash)
272250
}
273251
}

0 commit comments

Comments
 (0)