Commit b9f2dac
authored
Preallocate entries slice in DeserializeEntries (#285)
DeserializeEntries reads the entry count from the directory stream and
then builds the result with make([]EntryV3, 0) plus append. Because the
slice starts at zero capacity, append reallocates and copies the backing
array as it grows - 27 times for a full-planet leaf directory (~62k
entries) - and each discarded intermediate array is transient garbage.
The exact entry count is already known before the append loops, so size
the slice capacity to it up front. The decode logic is otherwise
unchanged and the returned entries are identical.
Decoding a 62,746-entry leaf (gzip), allocations measured with -benchmem:
before: 8,849,368 B/op 216 allocs/op
after: 1,579,005 B/op 190 allocs/op (-82% bytes, -26 allocs)1 parent 8a474e3 commit b9f2dac
1 file changed
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
327 | | - | |
328 | 326 | | |
329 | 327 | | |
330 | 328 | | |
| |||
338 | 336 | | |
339 | 337 | | |
340 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
| |||
0 commit comments