I see MemoryArena is registered.
Updated the gist with a MemoryArena version that is as close to possible as the current solution ( using threading ). I’m seeing pretty good timings.
env JULIA_NUM_THREADS=4 julia binarytrees-MemoryPool.jl
stretch tree of depth 6 check: 127
32 trees of depth 4 check: 992
long lived tree of depth 5 check: 63
0.198965 seconds (540.90 k allocations: 27.119 MiB)
stretch tree of depth 22 check: 8388607
2097152 trees of depth 4 check: 65011712
524288 trees of depth 6 check: 66584576
131072 trees of depth 8 check: 66977792
32768 trees of depth 10 check: 67076096
8192 trees of depth 12 check: 67100672
2048 trees of depth 14 check: 67106816
512 trees of depth 16 check: 67108352
128 trees of depth 18 check: 67108736
32 trees of depth 20 check: 67108832
long lived tree of depth 21 check: 4194303
2.291580 seconds (106 allocations: 5.297 KiB)
=========
env JULIA_NUM_THREADS=4 julia binarytrees-current.jl
Thread count: 4
stretch tree of depth 6 check: 127
32 trees of depth 4 check: 992
long lived tree of depth 5 check: 63
0.306586 seconds (1.34 M allocations: 67.345 MiB, 4.36% gc time)
stretch tree of depth 22 check: 8388607
2097152 trees of depth 4 check: 65011712
524288 trees of depth 6 check: 66584576
131072 trees of depth 8 check: 66977792
32768 trees of depth 10 check: 67076096
8192 trees of depth 12 check: 67100672
2048 trees of depth 14 check: 67106816
512 trees of depth 16 check: 67108352
128 trees of depth 18 check: 67108736
32 trees of depth 20 check: 67108832
long lived tree of depth 21 check: 4194303
1.923280 seconds (219 allocations: 153.674 MiB, 3.44% gc time)