Software Engineering
Python's Hidden Startup Tax: 400ms Delays Plague Top Packages, New Study Reveals
A comprehensive analysis of import costs across Python's most-used libraries shows startup delays are severe for CLI tools and serverless applications—though bytecode caching and lazy loading offer relief.
Every Python program incurs an invisible cost the moment it starts: the time needed to load imported modules. While this overhead vanishes during steady-state operation, it becomes a critical bottleneck for command-line tools, test runners, and serverless functions that spawn many short-lived processes. A new research paper has quantified just how severe this problem is across Python's ecosystem.
The Scale of the Import Problem#
Researchers examined the 500 most-downloaded packages from PyPI across multiple Python releases and platforms, measuring import startup costs in 66,816 separate tests. The findings paint a troubling picture: import times are heavily skewed, with a median cost of 12.3 milliseconds on macOS but a 99th-percentile penalty reaching 400 ms. For packages with import times above 2 milliseconds, the standard library accounts for the lion's share of the delay—68% on macOS and 79% on Linux with network storage.
The implications are stark. Packages containing native libraries face an additional security assessment each time they load in a fresh environment, multiplying the cold-start penalty. Precompiling bytecode helps significantly—removing 92% of the penalty for the median package on macOS—but on Linux it can nearly eliminate the problem entirely. However, packages with compiled extensions still experience substantial overhead.
Growth Trends and CPython Impacts#
A package's own import code grows by a median of 4.0% per year, though updating dependencies alongside each release has minimal effect on this trajectory. More concerning, CPython 3.14 actually makes the situation worse: while it runs package code faster than version 3.9, it imports slower standard-library modules, resulting in a net 1.16x slowdown for the median package.
Lazy Loading Emerges as a Solution#
Python 3.15 introduces explicit lazy imports (PEP 810), a feature that addresses these startup delays by deferring module initialization. Under global lazy loading mode, dependent imports drop to 0.41x of their original cost. However, the transition is not seamless: 38 of 461 packages tested failed under lazy mode, often only when developers first accessed a lazy-loaded name.
Submodules that dependents import beyond the top level add minimal overhead for most packages, though a small cohort experiences delays up to 50 milliseconds on Linux.