Why Python Is Perceived as Slow and How to Make It Faster
The article explains that Python’s reputation for slowness stems more from algorithmic choices and costly import patterns than the language itself, and it offers practical measurements, tooling insights, and optimization suggestions to improve Python’s performance in real‑world projects.
Python is often criticized for being slow, but the real bottleneck is usually the algorithm or hidden costs such as import overhead, not the language itself.
The author, a professional Python developer, shares personal experience and notes that many developers overlook how their code impacts overall performance, especially when libraries are used by thousands of users.
Typical tools in a Python workflow— pip for installing packages, virtualenv for isolated environments, and pytest for testing—are examined with timing examples showing that even simple commands can take noticeable seconds, and that these measurements become larger with many dependencies.
<code>time pip --version
0.34 seconds
time virtualenv -p $(which python3) venv
6.24 seconds
time pytest # in an EMPTY directory
0.32 seconds
time pip install pytest # already installed!!!
0.85 seconds</code>The author emphasizes that the slowdown is often due to the toolchain itself, which can be an order of magnitude slower than the actual work being performed.
Import statements are highlighted as a major hidden cost. Importing modules like requests implicitly loads heavy dependencies such as urllib2 , and patterns like conditional imports with try/except add extra latency (e.g., importing numpy can take ~200 ms on the author’s machine).
<code>try:
import numpy
NUMPY_AVAILABLE = True
except ImportError:
NUMPY_AVAILABLE = False</code>These import costs affect startup time, especially in web frameworks like Django, where eliminating unnecessary imports (e.g., pytz’s timezone database parsing) saved about 100 ms per worker start.
The article warns against the “10 ms is nothing” mindset, noting that when such small delays are multiplied by millions of executions, they become significant, and incremental slowdowns can quickly add up to noticeable performance regressions.
To address these issues, the author proposes several actions:
Replace pytest with a faster runner (e.g., a custom tool called hammett ) or push for major performance improvements in pytest .
Cache results in pip so that repeated installations are invisible to the user.
Optimize virtualenv by reducing the number of files written (the author notes recent improvements cut setup time from 6.4 s to 0.8 s).
Write benchmarks to compare Python tools against equivalents in other languages, establishing a clear performance baseline.
In the update, the author acknowledges that the virtualenv team has dramatically improved startup speed, praising the effort.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.