Gradual typing has gained popularity as a design choice for integrating static and dynamic typing within a single language. Several practical languages have adopted gradual typing to offer programmers the flexibility to annotate their programs as needed. Meanwhile there is a key challenge of unexpected performance degradation in partially typed programs. The execution speed may significantly decrease when simply adding more type annotations. Prior studies have investigated strategies of selectively adding type annotations for better performance. However, they are restricted in substantial compilation time, which impedes the practical usage. This paper presents a new technique to select a subset of type annotations derived by type inference for improving the execution performance of gradually typed programs. The advantage of the proposal is shorter compilation time by employing a lightweight, amortized approach. It selects type annotations along the data flows, which is expected to avoid expensive runtime casts caused by a value repeatedly crossing the boundaries between untyped and typed code. We demonstrate the applicability of our proposal, and conduct experiments to validate its effectiveness of improving the execution time on Reticulated Python. Our implementation supports a Python subset to select type annotations derived by an implemented, external type inference engine. Experiment results show that our proposal outperforms a naive strategy of using all type annotations derived by type inference among the benchmark programs. In comparison with an existing approach, the proposal achieves comparable execution speed and shows advantage of maintaining a more stable compilation time of deriving and selecting type annotations. Our results empirically indicate that the proposed technique is practical within Reticulated Python for mitigating the performance bottleneck of gradually typed programs.
翻译:渐进类型作为一种将静态类型与动态类型集成于单一语言的设计选择已获得广泛关注。多个实用语言采用渐进类型,为程序员提供了按需标注程序的灵活性。然而,部分类型化程序中存在的意外性能下降问题构成关键挑战。简单地增加类型标注可能导致执行速度显著降低。已有研究探讨了选择性添加类型标注以提升性能的策略,但这些方法存在编译时间过长的局限性,阻碍了实际应用。本文提出一种新技术,通过选择类型推断所生成类型标注的子集来改善渐进类型化程序的执行性能。该方案的优势在于采用轻量级摊销方法,从而缩短编译时间。该方法沿数据流路径选择类型标注,有望避免因值反复跨越无类型代码与类型化代码边界而产生的高开销运行时强制转换。我们论证了该方案的适用性,并通过实验验证其在Reticulated Python上改善执行时间的有效性。我们的实现支持Python子集,能够选择由已实现的外部类型推断引擎推导出的类型标注。实验结果表明,在基准测试程序中,本方案优于直接使用类型推断生成全部类型标注的朴素策略。与现有方法相比,本方案实现了相当的执行速度,并展现出在推导与选择类型标注过程中保持更稳定编译时间的优势。实验结果从实证角度表明,所提技术在Reticulated Python中具有实用性,能够有效缓解渐进类型化程序的性能瓶颈。