Python Threads vs Processes vs Asyncio: Same Code, 28× Faster or Slower (the GIL Explained)

Опубликовано: 17 Август 2026
на канале: brevfeed
10
1

Python hands you three tools with confident names — threading, multiprocessing,
asyncio — and reaching for the wrong one makes your code run SLOWER than the
plain loop you started with. This video measures exactly when each one wins.

The trap, in two numbers from one machine: a batch of CPU work goes from 4.9s
to 5.1s on threads (slower!); a batch of I/O work goes from 3.2s to 0.11s on
threads (28× faster). Same tool, same machine, opposite verdicts. The whole
game is one question — is your work CPU-bound or I/O-bound — and the ranking of
the tools inverts between them.

What we cover:
• Two workloads benchmarked across every tool (sequential, threading,
multiprocessing, asyncio, numpy)
• The GIL: the single mechanism that explains every result — why threads
serialise on CPU work but overlap for free on I/O
• When to use each: threads for waiting, processes for computing, asyncio for
waiting at massive scale
• Vectorisation — the option nobody lists, and it beat all three (numpy 9.8×
from zero concurrency)
• The 2024 change: Python 3.13/3.14 free-threading (no-GIL) takes threads from
~0.9× to ~8× on CPU work — and the single-thread tax that fell from 1.54× to
1.17× in one release

The one-line version: the win is matching the tool to the shape of the work —
and the first question is never "how many cores," it's "is this code even doing
work worth parallelising?"

📖 Full write-up with every benchmark table, the decision tree, and the code:
https://brevfeed.com/blog/python-para...

Part of the Python-at-scale series:
▶ 117 GB of Parquet, 9 hours → 9 seconds:
https://brevfeed.com/blog/python-parq...
▶ Row vs Column storage: https://brevfeed.com/blog/row-vs-colu...
▶ File formats (CSV/JSON/Avro/Parquet/ORC):
https://brevfeed.com/blog/file-format...

Rig: two workloads (CPU-bound trig sum over 20M integers; 64 I/O calls of 50ms)
across sequential/threading/multiprocessing/asyncio/numpy, plus a free-threaded
experiment on CPython 3.13t and 3.14t. 16 logical cores, wall clock, best of
three; every method returns the same answer as a correctness check.

#python #concurrency #gil #asyncio #multiprocessing #threading #numpy #performance