@@ -25,26 +25,6 @@ import (
25
25
"golang.org/x/sync/errgroup"
26
26
)
27
27
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
-
48
28
// lookup is an internal structure used to efficiently determine the layer in
49
29
// which a state entry resides.
50
30
type lookup struct {
@@ -159,7 +139,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
159
139
for accountHash := range diff .states .accountData {
160
140
list , exists := l .accounts [accountHash ]
161
141
if ! exists {
162
- list = getSlice ( )
142
+ list = make ([]common. Hash , 0 , 16 )
163
143
}
164
144
list = append (list , state )
165
145
l .accounts [accountHash ] = list
@@ -178,7 +158,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
178
158
for slotHash := range slots {
179
159
list , exists := subset [slotHash ]
180
160
if ! exists {
181
- list = getSlice ( )
161
+ list = make ([]common. Hash , 0 , 16 )
182
162
}
183
163
list = append (list , state )
184
164
subset [slotHash ] = list
@@ -212,7 +192,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
212
192
if i == 0 {
213
193
list = list [1 :]
214
194
if cap (list ) > 1024 {
215
- list = append (getSlice ( ), list ... )
195
+ list = append (make ([]common. Hash , 0 , len ( list ) ), list ... )
216
196
}
217
197
} else {
218
198
list = append (list [:i ], list [i + 1 :]... )
@@ -227,7 +207,6 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
227
207
if len (list ) != 0 {
228
208
l .accounts [accountHash ] = list
229
209
} else {
230
- returnSlice (list )
231
210
delete (l .accounts , accountHash )
232
211
}
233
212
}
@@ -252,7 +231,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
252
231
if i == 0 {
253
232
list = list [1 :]
254
233
if cap (list ) > 1024 {
255
- list = append (getSlice ( ), list ... )
234
+ list = append (make ([]common. Hash , 0 , len ( list ) ), list ... )
256
235
}
257
236
} else {
258
237
list = append (list [:i ], list [i + 1 :]... )
@@ -267,7 +246,6 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
267
246
if len (list ) != 0 {
268
247
subset [slotHash ] = list
269
248
} else {
270
- returnSlice (subset [slotHash ])
271
249
delete (subset , slotHash )
272
250
}
273
251
}
0 commit comments