arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~

进口税:Python生态系统中启动成本的纵向测量

The Import Tax: A Longitudinal Measurement of Startup Cost in the Python Ecosystem

Trinath Sai Subhash Reddy Pittala

arXiv 2609.02753首次发表:更新:

AI 中文总结

该研究测量Python生态系统的导入启动成本,发现其呈偏态分布、增长集中于重尾,全局惰性导入虽降低成本但会导致部分包故障,为Python导入优化提供系统依据。

AI 中文摘要

Python程序在每次进程启动时都要为其导入操作付出代价,这种成本在稳态基准测试中不可见,但对于命令行工具、测试工作进程和无服务器冷启动而言却占主导地位。Python 3.15添加了显式惰性导入(PEP 810),这主要是基于轶事证据;目前尚未有针对生态系统导入成本的系统测量研究。我们开展了相关测量:对PyPI上下载量最高的500个包,在五年发布周期内按季度采样,在两个平台(Apple M5/macOS和Intel Xeon/Linux)上的六个CPython版本(3.9-3.14)下进行测量,总共完成63431次测量,同时还直接测量了3.15的全局惰性导入模式。导入成本呈现严重的偏态分布:一半的包导入耗时在6毫秒以内,但第99百分位的耗时为354毫秒;安装后的首次导入成本是后续导入的3-22倍(源于字节码编译);导入包的子模块成本最高可达基准测试报告的顶级导入成本的294倍。中位数包的成本每年仅增长1.6%-2.4%,但平均值每年增长11%-13%:增长集中在重尾部分。较新的解释器在macOS上导入相同代码的速度慢1.16倍,但在Linux上并非如此;单个点版本(3.11.5与3.11.16)的成本波动达1.34倍。全局惰性模式使导入语句几乎免费,但会导致414个顶级包中的8个出现故障。测量工具和数据集可应要求提供。

英文摘要

Python programs pay for their imports at every process start, a cost that is invisible in steady-state benchmarks but dominant for command-line tools, test workers, and serverless cold starts. Python 3.15 adds explicit lazy imports (PEP 810) largely on anecdotal evidence; no systematic measurement of the ecosystem's import cost exists. We present one: the 500 most-downloaded PyPI packages, sampled quarterly over five years of releases, measured under six CPython versions (3.9-3.14) on two platforms (Apple M5/macOS and Intel Xeon/Linux), for 63,431 measurements in total, plus direct measurement of 3.15's global lazy-import mode. Import cost is heavily skewed: half of packages import in under 6 ms, but the 99th percentile is 354 ms, the first import after installation costs 3-22x more (bytecode compilation), and importing a package's submodules costs up to 294x more than the top-level import that benchmarks report. The median package's cost grows only +1.6-2.4%/year, but the mean grows +11-13%/year: growth is concentrated in a heavy tail. Newer interpreters import the same code 1.16x slower on macOS, but not on Linux, and a single point release (3.11.5 vs. 3.11.16) swings cost by 1.34x. Global lazy mode makes import statements essentially free, yet breaks 8 of 414 top packages. Harness and dataset are available on request.

Comments11 pages, 4 figures, 1 table

论文原文

arXiv 摘要页 · PDF 原文 · HTML 原文

↑