No time to idle about: Profiling import time in Python
summary
Python 3.7 exposes per-module timings via the -X importtime runtime flag and that data can be parsed, turned into a tree/graph, and visualised with flamegraph/tuner SVGs to reveal that a single import can dominate startup (examples show ~11s and a 10× gap). A small Python wrapper reproduces similar timing on 3.4–3.6, pydeps is extended to show import times and connectedness, and a combined metric (time, number of importers, unique attribute access) picks actionable targets for fixes like lazy imports or lazy instantiation which measurably reduce CLI startup.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 1:25The problem
- 3:36Different approaches
- 6:45The hack
- 8:04Visualization
- 10:30Tuner
- 11:23Is import a tree
- 13:29Paid EPS
- 17:14Node size
- 19:18Unique attribute access
- 21:19Improvements
- 24:42Conclusion
related talks
30mLazy imports and the art of interpreter procrastination
32mProfiling at the speed of light
01h 31mDebugging and profiling techniques
29m"from where?!? import what?!?"
30mThe Virtues of Being Lazy
30mHow to Tune your Python Analysis Pipeline: A Profiler Guide
53mRethinking How We're Linking: What to do when speeding...
28mImport Deep Dive
