Skip to content

Commit 8d97803

Browse files
authored
perf: speed up iter, range, scan methods with Rc<Node> (#356)
This PR improves iteration performance by storing nodes as Rc<Node<K>>. The change is inspired by the Entry API PoC in #251, but applied separately to avoid breaking changes. btreeset: ``` Summary: instructions: status: Regressions and improvements 🔴🟢 counts: [total 100 | regressed 7 | improved 40 | new 0 | unchanged 53] change: [max +2.21K | p75 -179.95K | median -207.33K | p25 -620.79K | min -2.49M] change %: [max +5.01% | p75 -0.04% | median -1.11% | p25 -5.50% | min -11.48%] ``` btreemap: ``` Summary: instructions: status: Regressions and improvements 🔴🟢 counts: [total 285 | regressed 3 | improved 8 | new 0 | unchanged 274] change: [max +5.34M | p75 +411.31K | median +146.65K | p25 +97.32K | min -1.49M] change %: [max +3.36% | p75 +0.06% | median +0.03% | p25 +0.01% | min -10.92%] ``` Most of the improved benchmarks related to `iter`, `range`, `scan` methods. Some regressions are small and limited to benchmarks not involving traversal. UPD(from [comment](#356 (comment))): At first glance using `Rc<Node<K>>` should not help since we don't explicitly clone `Node` anywhere. The improvement comes from **avoiding repeated moves of large value**. `Node` is fairly big (multiple fields and vectors) comparing to `Rc`, so moving it around during iteration adds overhead. Switching to `Rc` makes those moves much cheaper, it's just a pointer copy.
1 parent d73b331 commit 8d97803

3 files changed

Lines changed: 392 additions & 388 deletions

File tree

0 commit comments

Comments
 (0)