Array-of-structures (AoS) to structure-of-arrays (SoA) is a classic compiler transformation that improves memory locality and enables data-parallel execution. Existing AoS-to-SoA transformations primarily target regular, array-based programs in imperative languages like C and C++. In contrast, many applications manipulate tree-shaped data structures, for example, ASTs in compilers, DOM trees in browsers, and k-d trees in scientific workloads. Prior work improves the performance of functional programs operating on such data by serializing algebraic datatypes (ADTs) into contiguous memory buffers. However, these representations interleave fields within a single buffer, similar to AoS layouts. We introduce factored, multi-buffer layouts that store different ADT fields in separate buffers, enabling SoA-like layouts for serialized recursive data structures. We formalize this approach in SoCal, a language for generating factored ADT representations, and implement it in a compiler called Colobus. Colobus automatically transforms functional programs to operate over a serialized, factored layout of recursive ADTs. Our evaluation shows a 1.46x geometric mean speedup on a suite of tree-processing benchmarks.
翻译:数组结构体(AoS)到结构体数组(SoA)是一种经典的编译器变换,可改善内存局部性并支持数据并行执行。现有的AoS到SoA变换主要针对C和C++等命令式语言中基于数组的规则程序。相比之下,许多应用程序需要处理树形数据结构,例如编译器中的抽象语法树(AST)、浏览器中的DOM树以及科学计算中的k-d树。先前的工作通过将代数数据类型(ADT)序列化为连续内存缓冲区,提升了处理此类数据的函数式程序的性能。然而,这些表示方式会在单个缓冲区中交错存储各字段,类似于AoS布局。我们引入了分解的多缓冲区布局,将不同ADT字段存储于独立缓冲区中,从而为序列化递归数据结构实现类似SoA的布局。我们在SoCal语言中形式化了该方法(SoCal是一种用于生成分解ADT表示的语言),并在名为Colobus的编译器中实现了该方案。Colobus自动转换函数式程序,使其在序列化且分解的递归ADT布局上运行。在树处理基准测试集上,我们的评估显示几何平均加速比为1.46倍。