Skip to content

📊 Benchmarks CPU-bound tasks in Python 3.13 to compare performance with and without the GIL, as presented at PyCon Wrocław 2024. 💻⚙️

Notifications You must be signed in to change notification settings

krynecouk/kill-gil

Repository files navigation

Kill GIL

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

Prerequisites

  • uv
  • python3.13t

Execution

With GIL

PYTHON_GIL=1 uv run <script>.py

Without GIL

PYTHON_GIL=0 uv run <script>.py

Using the Script

Alternatively, use the included script to run both benchmarks:

./run.sh

Results

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:

  1. GIL prevents any parallelization of CPU-bound tasks, making it impossible to improve performance using threads.

  2. Threads with frequent access to shared memory do not scale well.

With GIL

===== 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  =====

Without GIL

===== 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  =====

Code Images

About

📊 Benchmarks CPU-bound tasks in Python 3.13 to compare performance with and without the GIL, as presented at PyCon Wrocław 2024. 💻⚙️

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published