This project accompanies my talk at PyCon Wrocław 2024, titled "Kill GIL: How Python 3.13 Changes Concurrent Programming". It benchmarks dummy CPU-bound tasks to compare performance with and without the Global Interpreter Lock (GIL) in Python 3.13.
- Presentation slides: Link
- Presentation recording: TBD
uv
python3.13t
PYTHON_GIL=1 uv run <script>.py
PYTHON_GIL=0 uv run <script>.py
Alternatively, use the included script to run both benchmarks:
./run.sh
The results of the benchmark vary not only between machines but also between runs. This is because it is up to the operating system to decide which CPU core a thread should be assigned to. However, the key takeaways from the presentation remain the same:
-
GIL prevents any parallelization of CPU-bound tasks, making it impossible to improve performance using threads.
-
Threads with frequent access to shared memory do not scale well.
===== Running single_thread.py =====
Execution time: 6.459282 seconds
Final counter value: 100000000
===== Finished =====
===== Running multi_thread_share.py =====
Execution time: 6.744378 seconds
Final counter value: 100000000
===== Finished =====
===== Running multi_thread_share_lock.py =====
Execution time: 23.893897 seconds
Final counter value: 100000000
===== Finished =====
===== Running multi_thread_private.py =====
Execution time: 6.728547 seconds
Final counter value: 100000000
===== Finished =====
===== Running single_thread.py =====
Execution time: 6.473970 seconds
Final counter value: 100000000
===== Finished =====
===== Running multi_thread_share.py =====
Execution time: 10.617835 seconds
Final counter value: 11665934
===== Finished =====
===== Running multi_thread_share_lock.py =====
Execution time: 175.884980 seconds
Final counter value: 100000000
===== Finished =====
===== Running multi_thread_private.py =====
Execution time: 1.605419 seconds
Final counter value: 100000000
===== Finished =====