一句话:通过大规模合成与真实项目数据,系统测量并字节码级解释 Python 惯用法相对非惯用写法的性能差异。
Python 开发者常对惯用法(idioms)的性能影响感到困惑,现有讨论多依赖轶事式玩具代码或个人项目经验,结果相互矛盾,缺乏大规模系统证据。本文为九种 Python 惯用法构建了 24,126 对非惯用法与功能等价的惯用法代码合成数据集,并复用包含 54,879 对代码的真实项目数据集;作者设计可靠的性能测量方法,比较惯用法相对非惯用法带来的加速或减速,分析合成代码与真实项目代码的性能差异、代码特征与性能变化的关系,并在字节码层面追溯性能变化的根因。最后总结出可操作的 Python 惯用法使用建议。
The usage of Python idioms is popular among Python developers in a formative study of 101 Python idiom performance related questions on Stack Overflow, we find that developers often get confused about the performance impact of Python idioms and use anecdotal toy code or rely on personal project experience which is often contradictory in performance outcomes. There has been no large-scale, systematic empirical evidence to reconcile these performance debates. In the paper, we create a large synthetic dataset with 24,126 pairs of non-idiomatic and functionally-equivalent idiomatic code for the nine unique Python idioms identified in [1], and reuse a large real-project dataset of 54,879 such code pairs provided in [1]. We develop a reliable performance measurement method to compare the speedup or slowdown by idiomatic code against non-idiomatic counterpart, and analyze the performance discrepancies between the synthetic and real-project code, the relationships between code features and performance changes, and the root causes of performance changes at the bytecode level. We summarize our findings as some actionable suggestions for using Python idioms.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{ZhangXXXZL23,
title = {Faster or Slower? Performance Mystery of Python Idioms Unveiled with Empirical Evidence},
author = {Zejun Zhang and Zhenchang Xing and Xin Xia and Xiwei Xu and Liming Zhu and Qinghua Lu},
booktitle = {ICSE},
year = {2023},
doi = {10.1109/icse48619.2023.00130}
}