Exploring the performance potential of a GIL-free Python
What’s happening?
One of the most anticipated changes in Python (removal of the GIL — see PEP 703) is ready to test right now. The current pre-release version of Python (3.13.0b4) has experimental support for running with the global interpreter lock disabled when built with the --disable-gil
flag. Pythons built with this flag are also referred to as free-threaded
versions of Python.
NB Work on this is still ongoing, so bugs are to be expected. Don’t use this version on production systems.
In this article, I’ll take you through how to build this version of Python and show some examples of code with and without the GIL enabled to see what differences it makes to run times.
Why does this matter?
In a word, “performance”.
Because free-threaded execution can use all the available cores on your system simultaneously, code will often run faster. As data scientists, and ML or data engineers this applies not only to your code but also to the code that builds the systems, frameworks, and libraries that you rely on.
Many machine learning and data science tasks are CPU-intensive, particularly during model…