一句话:TASTyTruffle 解释带类型的 TASTy IR,通过类型具体化和 JIT 特化泛型代码,提升参数多态性能。
参数多态的实现方式显著影响性能:JVM 常用类型擦除,以统一表示泛型数据,导致装箱和间接访问,并丢失可优化泛型代码的类型信息。TASTyTruffle 是 Scala 子集的实现,它解释未擦除泛型类型的 TASTy 类型化中间表示而非 JVM 字节码。借助精确类型信息,它把类型具体化为运行时可传递对象,支持泛型值的无装箱异构表示,并通过特化生成可由 JIT 优化的单态副本。在小型基准上,其性能与标准 JVM 实现相当;当泛型代码用于多种类型时,持续优于 JVM,并能发现擦除字节码无法揭示的优化机会。
Parametric polymorphism enables programmers to express algorithms independently of the types of values that they operate on. The approach used to implement parametric polymorphism can have important performance implications. One popular approach, erasure, uses a uniform representation for generic data, which entails primitive boxing and other indirections that harm performance. Erasure destroys type information that could be used by language implementations to optimize generic code. We present TASTyTruffle, an implementation for a subset of the Scala programming language. Instead of JVM bytecode, TASTyTruffle interprets Scala's TASTy intermediate representation, a typed representation wherein generic types are not erased. TASTy's precise type information empowers TASTyTruffle to implement generic code more effectively. In particular, it allows TASTyTruffle to reify types as run-time objects that can be passed around. Using reified types, TASTyTruffle supports heterogeneous box-free representations for generic values. TASTyTruffle also uses reified types to specialize generic code, producing monomorphic copies of generic code that can be easily and reliably optimized by its just-in-time (JIT) compiler. Empirically, TASTyTruffle is competitive with standard JVM implementations on a small set of benchmark programs; when generic code is used with multiple types, TASTyTruffle consistently outperforms the JVM. The precise type information in TASTy enables TASTyTruffle to find additional optimization opportunities that could not be uncovered with erased JVM bytecode.
@article{paperbot1890,
title = {TASTyTruffle: Just-in-Time Specialization of Parametric Polymorphism},
author = {Matt D'Souza and James You and Ondřej Lhoták and Aleksandar Prokopec},
journal = {Proceedings of the ACM on Programming Languages},
volume = {7},
number = {OOPSLA2},
year = {2023},
doi = {10.1145/3622853}
}