That seems to be a good idea. Iβve done this along with adding automatic compaction when blocks are shrunk and now were around 90% of croaringβs speed on this benchmark
.
Of course that means 2 allocations instead of one and a slightly less happy deinit. But I can accept that.
zig build bench -Doptimize=ReleaseFast
$ zig build bench -Doptimize=ReleaseFast
--------------------------------------------------
overall:
--------------------------------------------------
CRoaring: 11430 ops 20.698ms 0.55MB ops/sec
ZRoaring: 11430 ops 22.894ms 0.50MB ops/sec
ratio -- 0.90 π₯
--------------------------------------------------
individual ops: speed=ops/sec
--------------------------------------------------
op cr speed zr speed # ratio
--------------------------------------------------
clear 1.62MB 35.25MB 240 21.82 β‘
run_optimize 0.61MB 0.60MB 365 0.99 ππ»
shrink_to_fit 4.17MB 1.20MB 330 0.29 π©
portable_serialize 0.70MB 0.94MB 105 1.34 β‘
frozen_serialize 2.31MB 2.28MB 85 0.99 ππ»
minimum 32.69MB 34.56MB 580 1.06 ππ»
maximum 14.55MB 7.65MB 585 0.53 π©
add 12.09MB 10.37MB 2200 0.86 π₯
rank 10.29MB 9.69MB 25 0.94 ππ»
select 8.72MB 8.43MB 30 0.97 ππ»
contains 22.46MB 22.67MB 580 1.01 ππ»
add_many 2.52MB 2.86MB 915 1.13 β‘
add_range_closed 2.37MB 2.29MB 1545 0.96 ππ»
contains_range 16.02MB 17.40MB 570 1.09 β‘
range_cardinality 6.67MB 5.15MB 5 0.77 π₯
remove 11.65MB 11.98MB 630 1.03 ππ»
and 0.34MB 0.41MB 420 1.22 β‘
or 196.69kB 219.31kB 305 1.12 β‘
xor 157.98kB 180.81kB 375 1.14 β‘
andnot 217.86kB 0.33MB 320 1.50 β‘
lazy_or 161.72kB 239.00kB 250 1.48 β‘
or_inplace 0.32MB 0.34MB 390 1.05 ππ»
and_inplace 140.05kB 142.59kB 60 1.02 ππ»
is_subset 134.90kB 144.89kB 180 1.07 β‘
equals 26.55MB 6.86MB 30 0.26 π©
and_cardinality 0.74MB 1.05MB 40 1.42 β‘
or_cardinality 0.79MB 0.93MB 45 1.18 β‘
xor_cardinality 0.95MB 0.94MB 35 0.99 ππ»
andnot_cardinality 0.81MB 0.96MB 20 1.18 β‘
jaccard_index 0.88MB 1.06MB 40 1.20 β‘
or_many 19.59kB 12.23kB 130 0.62 π©