CAFS: 一种面向x86-64低基数整数数据的缓存感知频率排序
CAFS: A Cache-Aware Frequency Sort for Low-Cardinality Integer Data on x86-64
AI总结:
针对OLAP引擎中基数K远小于数组长度N的整数列,提出CAFS排序算法,利用AVX2 SIMD指令、Chao1基数估计和自适应调度,在K≪N时吞吐量达到pdqsort的1.7-3.1倍。
摘要:
OLAP引擎中的整数排序通常作用于基数$K$远小于数组长度$N$的列。经过分组阶段后,中间键列的$K$受限于不同分组键的数量,甚至列存储扫描通常也处理字典编码的分类字段,其中$K$不超过几千。对此类列进行比较排序仍需$Θ(N \log N)$次比较,基数排序仍需$Θ(N \cdot B/b)$次字节遍历,与$K$无关。本文描述CAFS,一种在x86-64上利用AVX2的整数排序。该算法结合了大小为一条缓存行的SIMD桶、基于1024个步长样本的Chao1基数估计(保存在堆分配的40 KB开放寻址表中),以及由溢出安全保护支持的自适应调度器。热循环是无分支的,使用AVX2 cmpeq配合movemask和tzcnt定位匹配通道。我们在全因子网格上对CAFS进行了基准测试,包括58个数组大小$N$(从$10^3$到$3 \cdot 10^7$)以及每个$N$下的密集$K$调度,共产生592770次计时运行,与pdqsort、IPS4o、vqsort、ska_sort和std::sort对比。在$K \ll N$范围内,CAFS的吞吐量是pdqsort的1.7-3.1倍,IPS4o的1.7-3.5倍,vqsort的1.2-2.3倍。与pdqsort的操作交叉点在$K \approx 1.3 \cdot 10^5$;与ska_sort在$K \approx 8.14 \cdot 10^5$;与vqsort在$K \approx 6.7 \cdot 10^5$;与IPS4o的曲线仅在$K = N$附近收敛。在五个基线中,只有vqsort在超过交叉点后实际超越CAFS,这使得vqsort阈值$K \approx 6.7 \cdot 10^5$成为CAFS操作范围的约束条件。
英文摘要:
Integer sorts in OLAP engines often run on columns whose cardinality $K$ is much smaller than the array length $N$. After a group-by stage the intermediate key column has $K$ bounded by the number of distinct group keys, and even a column-store scan typically operates on dictionary-encoded categorical fields where $K$ never exceeds a few thousand. A comparison sort on such a column still pays $Θ(N \log N)$ comparisons, and a radix sort still pays $Θ(N \cdot B/b)$ byte passes, irrespective of $K$. This paper describes CAFS, an integer sort that does exploit it on x86-64 with AVX2. The algorithm combines a SIMD bucket sized to one cache line, a Chao1 cardinality estimator over 1024 strided samples (kept in a heap-allocated 40 KB open-addressing table), and an adaptive dispatcher backed by a spill safety guard. The hot loop is branchless and uses AVX2 cmpeq together with movemask and tzcnt to locate the matching lane. We benchmarked CAFS on a full-factorial grid of 58 array sizes $N$ from $10^3$ to $3 \cdot 10^7$ with dense $K$ schedules per $N$, producing 592770 timed runs against pdqsort, IPS4o, vqsort, ska_sort, and std::sort. In the $K \ll N$ band the throughput is 1.7 to 3.1x that of pdqsort, 1.7 to 3.5x IPS4o, and 1.2 to 2.3x vqsort. The operational crossover against pdqsort is at $K \approx 1.3 \cdot 10^5$; against ska_sort, $K \approx 8.14 \cdot 10^5$; against vqsort, $K \approx 6.7 \cdot 10^5$; and against IPS4o the curves only converge near $K = N$. Of the five baselines, only vqsort actually overtakes CAFS once the crossover is passed, which makes the vqsort threshold at $K \approx 6.7 \cdot 10^5$ the binding constraint on the operational range of CAFS.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。