The VM already knew that: leveraging compile-time knowledge to optimize gradual typing

The VM already knew that: leveraging compile-time knowledge to optimize gradual typing
复制标题

虚拟机已经知道:利用编译时知识来优化渐进式打字

DOI:
10.1145/3133879
复制
发表时间:
2017
影响因子:
--
通讯作者:
Alexi Turcotte
Alexi Turcotte
中科院分区:
--
文献类型:
--
作者:
G. Richards;Ellen Arteca;Alexi Turcotte

文献摘要

被引文献

相似文献

使用动态语言的程序员希望约束和理解他们的程序的行为,可能会转向渐进类型语言,这种语言允许可选地指定类型,并在动态代码和静态代码之间的边界检查值。不幸的是,这些运行时检查的性能成本可能非常高,当存在检查时,执行速度会减慢至少10倍。用于动态语言的现代虚拟机(vm)使用推测技术来提高性能:如果一个特定的值被看到过一次,那么将来很可能会看到类似的值。它们将值的优化相关属性组合到可缓存的“形状”中,然后使用单个形状检查来包含对每个属性的检查。具有相同内存布局或相同字段类型的值具有相同的形状。这大大减少了在运行时执行动态代码所需执行的类型检查的数量。虽然这些检查对VM的优化非常有价值,但除了提高性能之外,对程序员几乎没有好处。本文提出了一种内在对象契约的设计,使逐渐类型语言的类型检查义务成为对象形状的内在部分,从而可以将运行时类型检查纳入现有的形状检查中,完全消除冗余检查。使用JavaScript的VM实现作为SafeTypeScript可靠性保证的目标,我们演示了在完全类型的代码中,相对于未检查的代码,平均减速7%,在悲观配置中不超过45%。
Programmers in dynamic languages wishing to constrain and understand the behavior of their programs may turn to gradually-typed languages, which allow types to be specified optionally and check values at the boundary between dynamic and static code. Unfortunately, the performance cost of these run-time checks can be severe, slowing down execution by at least 10x when checks are present. Modern virtual machines (VMs) for dynamic languages use speculative techniques to improve performance: If a particular value was seen once, it is likely that similar values will be seen in the future. They combine optimization-relevant properties of values into cacheable “shapes”, then use a single shape check to subsume checks for each property. Values with the same memory layout or the same field types have the same shape. This greatly reduces the amount of type checking that needs to be performed at run-time to execute dynamic code. While very valuable to the VM’s optimization, these checks do little to benefit the programmer aside from improving performance. We present in this paper a design for intrinsic object contracts, which makes the obligations of gradually-typed languages’ type checks an intrinsic part of object shapes, and thus can subsume run-time type checks into existing shape checks, eliminating redundant checks entirely. With an implementation on a VM for JavaScript used as a target for SafeTypeScript’s soundness guarantees, we demonstrate slowdown averaging 7% in fully-typed code relative to unchecked code, and no more than 45% in pessimal configurations.