哪些瞬态类型检查不是(几乎)免费的?
Which of My Transient Type Checks Are Not (Almost) Free?
摘要:
在渐进类型化语言中使用的一种类型检查形式是瞬态类型检查:每当一个对象“流过”带有类型注释的代码时,该对象会被动态检查,以确保它具有注释所需的方法。虚拟机中的即时编译和优化可以消除运行时瞬态类型检查的大部分开销。不幸的是,这种优化并不统一:有些类型检查会显著降低,甚至提高程序的性能。在本文中,我们改进了所谓的“Takikawa”协议,并使用它来识别哪些类型的注释对性能的影响最大。特别是,我们展示了当源代码中存在不同类型的注释时,如何绘制此类基准测试的性能曲线,以识别潜在的性能模式。我们通过测试蛾虚拟机来演示我们的方法:对于许多蛾的瞬态类型检查影响性能的基准测试,我们已经能够确定一个或两个特定的类型注释是可能的原因。如果没有这些类型注释,瞬态类型检查的性能影响就可以忽略不计。使用我们的技术,程序员可以通过删除昂贵的类型检查来优化程序,VM工程师可以识别编译器优化的新机会。
英文摘要:
One form of type checking used in gradually typed language is transient type checking: whenever an object 'flows' through code with a type annotation, the object is dynamically checked to ensure it has the methods required by the annotation. Just-in-time compilation and optimisation in virtual machines can eliminate much of the overhead of run-time transient type checks. Unfortunately this optimisation is not uniform: some type checks will significantly decrease, or even increase, a program's performance. In this paper, we refine the so called "Takikawa" protocol, and use it to identify which type annotations have the greatest effects on performance. In particular, we show how graphing the performance of such benchmarks when varying which type annotations are present in the source code can be used to discern potential patterns in performance. We demonstrate our approach by testing the Moth virtual machine: for many of the benchmarks where Moth's transient type checking impacts performance, we have been able to identify one or two specific type annotations that are the likely cause. Without these type annotations, the performance impact of transient type checking becomes negligible. Using our technique programmers can optimise programs by removing expensive type checks, and VM engineers can identify new opportunities for compiler optimisation.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。