Skip to content

Conversation

@mmsqe
Copy link

@mmsqe mmsqe commented Jan 16, 2026

  • prevent heap escape during iterator reuse by replacing *iter = IterG[T]{} with manual field clearing
  • improve performance in high-frequency iterator reuse scenarios
benchstat /private/tmp/bf.txt /private/tmp/af.txt
goos: darwin
goarch: arm64
pkg: github.com/tidwall/btree
cpu: Apple M4 Max
                                  │ /private/tmp/bf.txt │        /private/tmp/af.txt         │
                                  │       sec/op        │   sec/op     vs base               │
IteratorCreationAlloc/no_reuse-16           42.27n ± 1%   41.09n ± 2%   -2.79% (p=0.002 n=6)
IteratorCreationAlloc/reuse-16              15.78n ± 0%   13.29n ± 1%  -15.75% (p=0.002 n=6)
IteratorRelease-16                         11.740n ± 1%   9.377n ± 1%  -20.13% (p=0.002 n=6)
IteratorReuse/Recreate-16                   2.183µ ± 0%   2.200µ ± 1%        ~ (p=0.069 n=6)
IteratorReuse/Reuse-16                      2.189µ ± 1%   2.159µ ± 1%   -1.39% (p=0.002 n=6)
geomean                                     130.2n        119.4n        -8.25%

mmsqe added 2 commits January 16, 2026 16:49
manual clear iterator fields instead of struct assignment
to prevent heap allocation during high-frequency reuse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant