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) on largely anecdotal evidence. We measure the import cost of the 500 most-downloaded PyPI packages, every quarterly release since mid-2021, under six CPython versions (3.9-3.14) on two platforms (Apple M5/macOS and Intel Xeon/Linux), 66,816 cells in all, with targeted experiments that isolate individual effects. Values are for macOS (Linux in parentheses). Import cost is heavily skewed (median 12.3 ms, 99th percentile 400 ms). Among packages that import in more than 2 ms, namespace distributions excluded, the median package spends 68% of its import time in the standard library (68% on Linux with the interpreter on local storage, 79% on network storage). Precompiling bytecode removes almost all of the cold-start penalty on Linux and 92% of it for the median package on macOS, but only a third of the summed macOS penalty: packages with native libraries pay a security assessment of each library that the system has not seen before, again in every fresh environment. A package's own import code grows by a median 4.0% (5.0%) per year; installing each release with the dependencies of its time changes its trend by a median of only 0.15 (0.35) percentage points (CPython 3.9). CPython 3.14 runs package code faster than 3.9 but imports more and slower standard-library modules, a net 1.16x (1.07x) slowdown. Submodules that dependents import beyond the top level add nothing for the median package and at most 11.7 (49.5) ms for nine packages in ten. On CPython 3.15, global lazy mode cuts the imports that dependents perform to 0.41x (0.39x) of their cost, and 38 of 461 packages fail under it, many only on first use of a name. Harness, code, and dataset are public.
翻译:暂无翻译