You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
storage/cmdq: prevent iterator from escaping to heap
The iterator returned by `tree.MakeIter` was escaping to the heap
for two reasons:
1. it was capturing a reference to the tree itself.
2. it was pointing a slice into its own array.
This change addresses both of these problems and prevents the iterator
from escaping when used. The fixes were:
1. copy the tree's root pointer reference instead of a reference
to the tree itself.
2. avoid creating the self-referential slice reference. This mistakenly
escapes because of golang/go#7921, which
also caused issues with `bytes.Buffer` (https://golang.org/cl/133715).
This change also adds a new benchmark which demonstrates whether `MakeIter`
escapes or not:
```
name old time/op new time/op delta
BTreeMakeIter-4 131ns ±14% 25ns ± 1% -81.23% (p=0.000 n=9+9)
name old alloc/op new alloc/op delta
BTreeMakeIter-4 144B ± 0% 0B -100.00% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
BTreeMakeIter-4 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
```
Release note: None
0 commit comments