Skip to content

Gallop when one array container is much smaller than the other (fixes #912) - #913

Merged
lemire merged 1 commit into
masterfrom
fix-skewed-array-merge
Oct 21, 2026
Merged

lemire merged 1 commit into
masterfrom
fix-skewed-array-merge

Conversation

@lemire

@lemire lemire commented Oct 21, 2026

Copy link
Copy Markdown
Member

Fixes #912.

Problem

Since 5.2.4 (#904), the scalar union_uint16, difference_uint16 and xor_uint16 handle blocks of four values only while four values remain on each side. Everything else goes through the branchless one-value-at-a-time loop, whose load addresses depend on the previous comparison, so it costs several cycles per value. When one array container has a few values and the other has thousands, every value of the large side goes through that chain. OR and ANDNOT of a tiny bitmap against a 2000-value one became 3–5x slower than 5.2.3. On x64 the vectorized union and xor fall back to the scalar code below 8 values, so the regression shows up there as well, and in builds with ROARING_DISABLE_X64.

Fix

  • When one side is more than 8 times shorter (CROARING_SKEWED_MERGE_RATIO), the scalar union, difference and xor locate each value of the short side in the long side by galloping and copy the values in between in bulk.
  • Once fewer than four values remain on one side, the merges and the intersections (intersect_uint16, intersect_uint16_cardinality) gallop the same way when the other side still has many values. Otherwise they keep the existing branchless tail, which leaves the balanced case unchanged. Calling the gallop helper unconditionally there cost about 4% on balanced inputs with GCC.
  • On x64, union and xor skip the vectorized code when the sizes differ by more than 32 times (CROARING_SKEWED_VECTOR_MERGE_RATIO). ANDNOT skips difference_vector16 when one side has fewer than 8 values (it does not vectorize there) or is 128 times shorter. That path was 0.7–1.7 µs for 1–3 values even in 5.2.3.
  • The aliasing guarantees are preserved: the in-place union with buffer starting size_2 values before set_1, a_out == a1 for difference, and out equal to either input for intersection.

I picked the thresholds from a sweep on both machines.

Testing

  • ctest passes on macOS/arm64 and on x64 (default and -DROARING_DISABLE_X64=ON).
  • A differential test against a reference implementation compared every kernel (union_uint16, fast_union_uint16, in-place union, xor_uint16, difference_uint16 in and out of place, intersect_uint16 with out equal to either input, intersect_uint16_cardinality). It used sizes 0–4096, uniform and clustered data, under ASan and UBSan, with the ratio forced to 1, 8 and 10⁶ so that every path is exercised.

Benchmarks

New microbenchmarks/array_merge_bench (Google Benchmark): Or, OrInplace (small ⊂ large, the scenario of the issue), AndnotLargeMinusSmall, AndnotSmallMinusLarge, Xor and And. The small side has 1–128 values and the large side 256–3500, all in one 64K chunk. Balanced pairs guard the regular merge. Each benchmark cycles through 64 distinct random pairs so that the branch predictor does not learn one input.

The reporter's repro.c on an Apple M-series laptop went from 1470 / 1500 / 1600 ns on master (520 / 390 / 620 on 5.2.3) to 93 / 97 / 95 ns for or_inplace / or / andnot.

Selected rows, ns per operation (median of 3):

benchmark Mac: 5.2.3 / master / PR big4 SIMD: 5.2.3 / master / PR big4 scalar: 5.2.3 / master / PR
Or/1/2000 473 / 1850 / 126 923 / 2722 / 162 681 / 2746 / 160
OrInplace/1/2000 560 / 1674 / 132 393 / 2604 / 140 499 / 2626 / 137
AndnotLargeMinusSmall/1/2000 703 / 1749 / 126 729 / 716 / 157 695 / 2817 / 171
Xor/1/2000 855 / 1858 / 128 799 / 3279 / 160 760 / 3286 / 166
Or/8/3500 1106 / 2444 / 264 2661 / 3452 / 341 1945 / 3436 / 355
AndnotSmallMinusLarge/3/3500 870 / 4247 / 118 1589 / 1588 / 144 2347 / 7085 / 143
Or/32/2000 925 / 948 / 434 1480 / 1522 / 697 1483 / 1195 / 694
Xor/32/3500 2688 / 1404 / 461 2600 / 2906 / 725 2588 / 2302 / 774
Or/2000/2000 7992 / 7183 / 6937 1579 / 1603 / 1616 14831 / 10454 / 10485

Geometric mean over the 140 cases:

machine vs master vs 5.2.3
Apple M-series, Apple clang 3.50x faster 2.17x faster
big4, Xeon Gold 6548N, GCC 14.3, default (AVX2/AVX-512) 2.89x faster 2.05x faster
big4, -DROARING_DISABLE_X64=ON 3.96x faster 2.20x faster

Cases that do not take the new paths (balanced sizes, moderate skew) are unchanged within noise. The worst is +6 ns on AndnotLargeMinusSmall/8/256 with SIMD. One gap remains that this PR does not address: on Apple silicon, moderate skew (Or/500/2000, Or/128/256) is still about 2x slower than 5.2.3. There the old branchy merge beats both the branchless merge from #904 and galloping.

Full results:

Apple M-series laptop, macOS, Apple clang
benchmark 5.2.3 master this PR vs master
Or/1/256 122 289 92 3.14x
Or/2/256 144 379 107 3.56x
Or/3/256 156 432 114 3.79x
Or/8/256 164 269 146 1.84x
Or/32/256 190 325 293 1.11x
Or/128/256 316 664 629 1.05x
Or/1/2000 473 1850 126 14.72x
Or/2/2000 546 2420 140 17.34x
Or/3/2000 637 2603 148 17.53x
Or/8/2000 728 1498 203 7.38x
Or/32/2000 925 948 434 2.19x
Or/128/2000 1120 1387 1090 1.27x
Or/1/3500 615 2899 175 16.57x
Or/2/3500 889 4406 194 22.74x
Or/3/3500 999 4515 210 21.46x
Or/8/3500 1106 2444 264 9.25x
Or/32/3500 1526 1422 502 2.83x
Or/128/3500 1630 1813 1313 1.38x
Or/500/2000 1542 3513 3280 1.07x
Or/2000/2000 7992 7183 6937 1.04x
OrInplace/1/256 93 255 31 8.25x
OrInplace/2/256 108 315 34 9.24x
OrInplace/3/256 126 346 43 8.12x
OrInplace/8/256 152 211 82 2.57x
OrInplace/32/256 173 250 214 1.17x
OrInplace/128/256 242 432 426 1.02x
OrInplace/1/2000 560 1674 132 12.65x
OrInplace/2/2000 757 2298 150 15.28x
OrInplace/3/2000 843 2631 160 16.41x
OrInplace/8/2000 969 1384 209 6.62x
OrInplace/32/2000 1150 909 447 2.03x
OrInplace/128/2000 1489 1239 1093 1.13x
OrInplace/1/3500 1049 2632 212 12.40x
OrInplace/2/3500 1340 3885 229 17.00x
OrInplace/3/3500 1463 4374 243 17.97x
OrInplace/8/3500 1639 2406 291 8.26x
OrInplace/32/3500 1977 1399 548 2.55x
OrInplace/128/3500 2388 1705 1321 1.29x
OrInplace/500/2000 2579 2775 2719 1.02x
OrInplace/2000/2000 1139 684 668 1.02x
AndnotLargeMinusSmall/1/256 151 274 90 3.03x
AndnotLargeMinusSmall/2/256 188 368 106 3.46x
AndnotLargeMinusSmall/3/256 205 411 114 3.60x
AndnotLargeMinusSmall/8/256 219 265 146 1.82x
AndnotLargeMinusSmall/32/256 222 320 290 1.11x
AndnotLargeMinusSmall/128/256 300 650 651 1.00x
AndnotLargeMinusSmall/1/2000 703 1749 126 13.89x
AndnotLargeMinusSmall/2/2000 844 2236 139 16.05x
AndnotLargeMinusSmall/3/2000 912 2440 148 16.48x
AndnotLargeMinusSmall/8/2000 1082 1355 208 6.50x
AndnotLargeMinusSmall/32/2000 1283 857 440 1.95x
AndnotLargeMinusSmall/128/2000 1569 1237 1112 1.11x
AndnotLargeMinusSmall/1/3500 1103 2841 173 16.42x
AndnotLargeMinusSmall/2/3500 1390 3835 192 19.96x
AndnotLargeMinusSmall/3/3500 1524 4293 209 20.58x
AndnotLargeMinusSmall/8/3500 1777 2183 258 8.45x
AndnotLargeMinusSmall/32/3500 2043 1249 499 2.51x
AndnotLargeMinusSmall/128/3500 2583 1601 1309 1.22x
AndnotLargeMinusSmall/500/2000 1948 3307 3194 1.04x
AndnotLargeMinusSmall/2000/2000 10458 6934 6867 1.01x
AndnotSmallMinusLarge/1/256 93 248 53 4.64x
AndnotSmallMinusLarge/2/256 117 334 67 4.97x
AndnotSmallMinusLarge/3/256 125 377 79 4.77x
AndnotSmallMinusLarge/8/256 135 239 116 2.06x
AndnotSmallMinusLarge/32/256 162 298 292 1.02x
AndnotSmallMinusLarge/128/256 263 617 715 0.86x
AndnotSmallMinusLarge/1/2000 379 1807 62 29.34x
AndnotSmallMinusLarge/2/2000 502 2290 82 27.86x
AndnotSmallMinusLarge/3/2000 599 2489 99 25.27x
AndnotSmallMinusLarge/8/2000 707 1425 165 8.66x
AndnotSmallMinusLarge/32/2000 895 890 373 2.39x
AndnotSmallMinusLarge/128/2000 1011 1280 849 1.51x
AndnotSmallMinusLarge/1/3500 540 2839 65 43.70x
AndnotSmallMinusLarge/2/3500 867 3832 86 44.37x
AndnotSmallMinusLarge/3/3500 870 4247 118 35.87x
AndnotSmallMinusLarge/8/3500 1033 2359 215 10.97x
AndnotSmallMinusLarge/32/3500 1464 1309 414 3.16x
AndnotSmallMinusLarge/128/3500 1726 1684 1043 1.61x
AndnotSmallMinusLarge/500/2000 1276 3349 3326 1.01x
AndnotSmallMinusLarge/2000/2000 9010 6890 6878 1.00x
Xor/1/256 166 286 92 3.10x
Xor/2/256 214 373 108 3.45x
Xor/3/256 236 415 112 3.71x
Xor/8/256 284 272 145 1.87x
Xor/32/256 341 326 298 1.09x
Xor/128/256 492 649 646 1.01x
Xor/1/2000 855 1858 128 14.57x
Xor/2/2000 1068 2349 140 16.73x
Xor/3/2000 1148 2551 149 17.15x
Xor/8/2000 1433 1446 200 7.22x
Xor/32/2000 1650 951 400 2.38x
Xor/128/2000 2160 1363 950 1.43x
Xor/1/3500 1400 2996 171 17.52x
Xor/2/3500 1787 3977 198 20.07x
Xor/3/3500 2002 4419 212 20.79x
Xor/8/3500 2350 2431 266 9.12x
Xor/32/3500 2688 1404 461 3.05x
Xor/128/3500 3316 1920 1159 1.66x
Xor/500/2000 3617 3406 3418 1.00x
Xor/2000/2000 10061 6907 7146 0.97x
And/1/256 65 63 64 0.99x
And/2/256 51 48 49 0.99x
And/3/256 88 81 80 1.01x
And/8/256 129 251 112 2.23x
And/32/256 155 309 267 1.16x
And/128/256 273 636 625 1.02x
And/1/2000 78 71 72 0.99x
And/2/2000 60 59 58 1.01x
And/3/2000 111 107 106 1.01x
And/8/2000 119 113 114 0.99x
And/32/2000 752 921 562 1.64x
And/128/2000 944 1405 1235 1.14x
And/1/3500 89 85 84 1.01x
And/2/3500 75 69 73 0.95x
And/3/3500 131 123 119 1.03x
And/8/3500 150 138 138 1.00x
And/32/3500 342 318 304 1.04x
And/128/3500 1488 1862 1453 1.28x
And/500/2000 1742 3278 3156 1.04x
And/2000/2000 9720 6864 6835 1.00x
big4: Xeon Gold 6548N (Emerald Rapids), GCC 14.3, default build (AVX2/AVX-512)
benchmark 5.2.3 master this PR vs master
Or/1/256 160 417 80 5.21x
Or/2/256 227 530 88 6.00x
Or/3/256 237 552 97 5.72x
Or/8/256 300 351 171 2.05x
Or/32/256 258 305 270 1.13x
Or/128/256 219 270 273 0.99x
Or/1/2000 923 2722 162 16.77x
Or/2/2000 1167 3590 191 18.80x
Or/3/2000 1250 3902 206 18.94x
Or/8/2000 1644 2195 295 7.43x
Or/32/2000 1480 1522 697 2.19x
Or/128/2000 1031 1046 943 1.11x
Or/1/3500 1450 4760 202 23.54x
Or/2/3500 2062 6379 225 28.41x
Or/3/3500 2307 6893 248 27.84x
Or/8/3500 2661 3452 341 10.13x
Or/32/3500 2508 2621 805 3.25x
Or/128/3500 1687 1663 1473 1.13x
Or/500/2000 1085 1064 1054 1.01x
Or/2000/2000 1579 1603 1616 0.99x
OrInplace/1/256 75 352 40 8.77x
OrInplace/2/256 94 484 55 8.79x
OrInplace/3/256 98 547 69 7.92x
OrInplace/8/256 102 319 135 2.36x
OrInplace/32/256 130 277 244 1.13x
OrInplace/128/256 566 225 218 1.03x
OrInplace/1/2000 393 2604 140 18.57x
OrInplace/2/2000 512 3567 157 22.67x
OrInplace/3/2000 562 3939 178 22.19x
OrInplace/8/2000 718 2226 261 8.52x
OrInplace/32/2000 1080 1505 645 2.33x
OrInplace/128/2000 2298 1015 940 1.08x
OrInplace/1/3500 743 5101 211 24.20x
OrInplace/2/3500 860 6297 233 27.02x
OrInplace/3/3500 949 6982 255 27.36x
OrInplace/8/3500 1161 3946 343 11.50x
OrInplace/32/3500 1580 2565 776 3.31x
OrInplace/128/3500 2977 1703 1525 1.12x
OrInplace/500/2000 5244 1035 1033 1.00x
OrInplace/2000/2000 1930 1392 1391 1.00x
AndnotLargeMinusSmall/1/256 156 155 85 1.83x
AndnotLargeMinusSmall/2/256 183 183 92 1.99x
AndnotLargeMinusSmall/3/256 186 185 97 1.90x
AndnotLargeMinusSmall/8/256 105 104 109 0.96x
AndnotLargeMinusSmall/32/256 102 101 104 0.97x
AndnotLargeMinusSmall/128/256 109 110 112 0.98x
AndnotLargeMinusSmall/1/2000 729 716 157 4.57x
AndnotLargeMinusSmall/2/2000 932 928 188 4.94x
AndnotLargeMinusSmall/3/2000 1007 1009 201 5.02x
AndnotLargeMinusSmall/8/2000 395 395 299 1.32x
AndnotLargeMinusSmall/32/2000 415 416 436 0.95x
AndnotLargeMinusSmall/128/2000 441 441 474 0.93x
AndnotLargeMinusSmall/1/3500 1201 1196 197 6.07x
AndnotLargeMinusSmall/2/3500 1590 1573 223 7.06x
AndnotLargeMinusSmall/3/3500 1713 1723 246 7.01x
AndnotLargeMinusSmall/8/3500 610 613 337 1.82x
AndnotLargeMinusSmall/32/3500 693 694 685 1.01x
AndnotLargeMinusSmall/128/3500 739 744 732 1.02x
AndnotLargeMinusSmall/500/2000 670 666 666 1.00x
AndnotLargeMinusSmall/2000/2000 1142 1137 1146 0.99x
AndnotSmallMinusLarge/1/256 145 145 69 2.11x
AndnotSmallMinusLarge/2/256 175 174 83 2.09x
AndnotSmallMinusLarge/3/256 178 178 89 2.01x
AndnotSmallMinusLarge/8/256 87 86 89 0.96x
AndnotSmallMinusLarge/32/256 85 85 88 0.97x
AndnotSmallMinusLarge/128/256 102 103 105 0.98x
AndnotSmallMinusLarge/1/2000 644 643 79 8.15x
AndnotSmallMinusLarge/2/2000 851 851 109 7.81x
AndnotSmallMinusLarge/3/2000 925 925 130 7.13x
AndnotSmallMinusLarge/8/2000 260 259 233 1.11x
AndnotSmallMinusLarge/32/2000 301 299 297 1.01x
AndnotSmallMinusLarge/128/2000 344 358 345 1.04x
AndnotSmallMinusLarge/1/3500 1090 1090 85 12.88x
AndnotSmallMinusLarge/2/3500 1464 1464 118 12.36x
AndnotSmallMinusLarge/3/3500 1589 1588 144 11.00x
AndnotSmallMinusLarge/8/3500 394 393 268 1.47x
AndnotSmallMinusLarge/32/3500 468 470 471 1.00x
AndnotSmallMinusLarge/128/3500 535 535 539 0.99x
AndnotSmallMinusLarge/500/2000 645 665 640 1.04x
AndnotSmallMinusLarge/2000/2000 1138 1139 1153 0.99x
Xor/1/256 158 495 80 6.22x
Xor/2/256 195 632 86 7.36x
Xor/3/256 203 660 91 7.26x
Xor/8/256 242 430 158 2.73x
Xor/32/256 270 320 270 1.19x
Xor/128/256 340 320 321 1.00x
Xor/1/2000 799 3279 160 20.45x
Xor/2/2000 1078 4342 186 23.38x
Xor/3/2000 1270 4713 200 23.59x
Xor/8/2000 1538 2628 282 9.32x
Xor/32/2000 1538 1677 622 2.69x
Xor/128/2000 1593 1479 1338 1.10x
Xor/1/3500 1366 5757 198 29.06x
Xor/2/3500 1747 7732 218 35.53x
Xor/3/3500 1988 8369 238 35.17x
Xor/8/3500 2395 4139 325 12.75x
Xor/32/3500 2600 2906 725 4.01x
Xor/128/3500 2644 2435 2182 1.12x
Xor/500/2000 1871 1655 1643 1.01x
Xor/2000/2000 2914 2469 2468 1.00x
And/1/256 71 69 71 0.98x
And/2/256 59 59 61 0.98x
And/3/256 94 96 96 1.00x
And/8/256 90 87 89 0.99x
And/32/256 89 86 87 0.98x
And/128/256 105 99 106 0.94x
And/1/2000 85 85 86 0.99x
And/2/2000 79 80 80 1.00x
And/3/2000 124 126 126 1.00x
And/8/2000 135 135 137 0.98x
And/32/2000 344 349 345 1.01x
And/128/2000 366 363 363 1.00x
And/1/3500 91 91 92 0.99x
And/2/3500 86 86 86 1.00x
And/3/3500 134 134 135 0.99x
And/8/3500 147 147 149 0.98x
And/32/3500 421 421 424 0.99x
And/128/3500 606 599 603 0.99x
And/500/2000 564 557 554 1.01x
And/2000/2000 1079 1051 1077 0.98x
big4, same machine, -DROARING_DISABLE_X64=ON (scalar code)
benchmark 5.2.3 master this PR vs master
Or/1/256 144 410 79 5.19x
Or/2/256 182 525 87 6.06x
Or/3/256 195 548 95 5.77x
Or/8/256 243 329 156 2.11x
Or/32/256 304 402 371 1.08x
Or/128/256 722 900 898 1.00x
Or/1/2000 681 2746 160 17.17x
Or/2/2000 881 3617 187 19.36x
Or/3/2000 962 3932 203 19.38x
Or/8/2000 1207 2176 296 7.36x
Or/32/2000 1483 1195 694 1.72x
Or/128/2000 2300 2331 2166 1.08x
Or/1/3500 1152 4776 202 23.63x
Or/2/3500 1519 6448 229 28.15x
Or/3/3500 1642 6984 254 27.54x
Or/8/3500 1945 3436 355 9.68x
Or/32/3500 2358 1919 828 2.32x
Or/128/3500 3162 2878 2501 1.15x
Or/500/2000 5271 6111 6197 0.99x
Or/2000/2000 14831 10454 10485 1.00x
OrInplace/1/256 82 344 44 7.78x
OrInplace/2/256 113 475 59 8.09x
OrInplace/3/256 126 539 73 7.35x
OrInplace/8/256 148 309 132 2.34x
OrInplace/32/256 173 353 330 1.07x
OrInplace/128/256 526 639 636 1.00x
OrInplace/1/2000 499 2626 137 19.11x
OrInplace/2/2000 684 3580 156 22.92x
OrInplace/3/2000 801 3961 172 23.06x
OrInplace/8/2000 889 2218 263 8.45x
OrInplace/32/2000 1249 1187 641 1.85x
OrInplace/128/2000 1964 2328 2145 1.08x
OrInplace/1/3500 1008 5092 211 24.17x
OrInplace/2/3500 1211 6297 234 26.93x
OrInplace/3/3500 1291 6964 254 27.42x
OrInplace/8/3500 1625 3926 347 11.32x
OrInplace/32/3500 1975 1862 782 2.38x
OrInplace/128/3500 2811 2868 2499 1.15x
OrInplace/500/2000 4534 5018 5058 0.99x
OrInplace/2000/2000 2147 579 581 1.00x
AndnotLargeMinusSmall/1/256 144 434 88 4.95x
AndnotLargeMinusSmall/2/256 172 549 98 5.59x
AndnotLargeMinusSmall/3/256 175 573 108 5.33x
AndnotLargeMinusSmall/8/256 198 353 154 2.29x
AndnotLargeMinusSmall/32/256 205 439 403 1.09x
AndnotLargeMinusSmall/128/256 728 968 966 1.00x
AndnotLargeMinusSmall/1/2000 695 2817 171 16.50x
AndnotLargeMinusSmall/2/2000 891 3725 196 19.02x
AndnotLargeMinusSmall/3/2000 963 4033 209 19.31x
AndnotLargeMinusSmall/8/2000 1205 2285 300 7.61x
AndnotLargeMinusSmall/32/2000 1426 1334 709 1.88x
AndnotLargeMinusSmall/128/2000 2327 2510 2344 1.07x
AndnotLargeMinusSmall/1/3500 1166 4913 208 23.67x
AndnotLargeMinusSmall/2/3500 1529 6590 231 28.57x
AndnotLargeMinusSmall/3/3500 1643 7120 257 27.71x
AndnotLargeMinusSmall/8/3500 1949 3581 356 10.05x
AndnotLargeMinusSmall/32/3500 2300 2096 846 2.48x
AndnotLargeMinusSmall/128/3500 3167 3031 2642 1.15x
AndnotLargeMinusSmall/500/2000 5857 6560 6462 1.02x
AndnotLargeMinusSmall/2000/2000 16619 11130 11089 1.00x
AndnotSmallMinusLarge/1/256 186 429 66 6.52x
AndnotSmallMinusLarge/2/256 227 546 80 6.79x
AndnotSmallMinusLarge/3/256 238 569 86 6.65x
AndnotSmallMinusLarge/8/256 292 350 134 2.61x
AndnotSmallMinusLarge/32/256 330 433 392 1.10x
AndnotSmallMinusLarge/128/256 662 963 959 1.00x
AndnotSmallMinusLarge/1/2000 1007 2767 78 35.43x
AndnotSmallMinusLarge/2/2000 1236 3676 108 34.10x
AndnotSmallMinusLarge/3/2000 1345 3987 128 31.21x
AndnotSmallMinusLarge/8/2000 1690 2216 230 9.63x
AndnotSmallMinusLarge/32/2000 1961 1273 556 2.29x
AndnotSmallMinusLarge/128/2000 2629 2428 1757 1.38x
AndnotSmallMinusLarge/1/3500 1716 4845 84 57.34x
AndnotSmallMinusLarge/2/3500 2201 6545 118 55.49x
AndnotSmallMinusLarge/3/3500 2347 7085 143 49.59x
AndnotSmallMinusLarge/8/3500 2778 3495 266 13.15x
AndnotSmallMinusLarge/32/3500 3248 2008 669 3.00x
AndnotSmallMinusLarge/128/3500 3994 2985 2082 1.43x
AndnotSmallMinusLarge/500/2000 5326 6492 6438 1.01x
AndnotSmallMinusLarge/2000/2000 16681 11134 11074 1.01x
Xor/1/256 153 491 86 5.68x
Xor/2/256 184 627 85 7.34x
Xor/3/256 183 655 90 7.27x
Xor/8/256 213 399 139 2.86x
Xor/32/256 234 493 449 1.10x
Xor/128/256 1108 1113 1114 1.00x
Xor/1/2000 760 3286 166 19.84x
Xor/2/2000 985 4348 190 22.87x
Xor/3/2000 1069 4720 202 23.39x
Xor/8/2000 1337 2607 282 9.24x
Xor/32/2000 1604 1462 638 2.29x
Xor/128/2000 2525 2676 2090 1.28x
Xor/1/3500 1286 5754 202 28.52x
Xor/2/3500 1694 7729 231 33.42x
Xor/3/3500 1833 8368 255 32.84x
Xor/8/3500 2166 4105 353 11.62x
Xor/32/3500 2588 2302 774 2.97x
Xor/128/3500 3517 3253 2373 1.37x
Xor/500/2000 5858 7178 7159 1.00x
Xor/2000/2000 17955 12989 12791 1.02x
And/1/256 80 82 80 1.02x
And/2/256 60 59 59 1.01x
And/3/256 85 85 84 1.01x
And/8/256 139 325 144 2.26x
And/32/256 155 425 403 1.05x
And/128/256 609 877 882 0.99x
And/1/2000 93 93 91 1.03x
And/2/2000 79 79 79 1.00x
And/3/2000 118 118 118 1.00x
And/8/2000 135 136 135 1.01x
And/32/2000 1066 1404 991 1.42x
And/128/2000 2146 2332 2260 1.03x
And/1/3500 97 96 95 1.01x
And/2/3500 86 85 86 0.99x
And/3/3500 126 125 126 1.00x
And/8/3500 147 147 147 1.00x
And/32/3500 422 422 423 1.00x
And/128/3500 2809 2910 2744 1.06x
And/500/2000 5086 6032 6061 1.00x
And/2000/2000 14634 10108 10147 1.00x

Since 5.2.4, the scalar union, difference and symmetric difference of two
array containers handle blocks of four values only while four values remain
on each side, and step through everything else one branchless value at a
time. When one side holds a few values, every value of the other side goes
through that dependent chain, which made OR and ANDNOT of a tiny bitmap
against one with thousands of values 3 to 5 times slower than in 5.2.3.

When one side is more than 8 times shorter, union_uint16, difference_uint16
and xor_uint16 now locate each of its values in the long side by galloping
and copy the values in between in bulk. Once fewer than four values remain
on one side, the merges and the intersections do the same when many values
remain on the other. On x64, union and xor skip the vectorized code when
the sizes differ by more than 32 times, and the vectorized difference is
skipped when one side has fewer than 8 values or is 128 times shorter.

Adds microbenchmarks/array_merge_bench.

Fixes #912
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.

or and andnot much slower since 5.2.4 when one bitmap is small

1 participant