Python 3.13 beta release: feature-frozen, free threading option, experimental JIT compiler

Python 3.13 beta release: feature-frozen, free threading option, experimental JIT compiler

Python 3.13 beta 1 is out, with key new features including an option to disable the Global Interpeter Lock (GIL) for free threading, and an experimental just-in-time compiler, both of which can improve performance. The appearance of the beta also means that 3.13 is feature-frozen.

Most rankings – like this one from Redmonk – place Python as second only to JavaScript in popularity, with usage increasing thanks to its association with AI and machine learning. CPython though is relatively slow, the consequence being that performance is a focus of recent releases.

Version 3.13 includes what the release notes call “a basic JIT compiler” though currently disabled by default. The PEP (Python Enhancement Proposal) for this feature explains that this is a “particularly significant departure from the way CPython has traditionally executed Python code.” Python currently compiles to bytecode, which is interpreted at runtime. Python 3.12 already includes code to break down instructions into smaller micro-operations and then optimize them, but the overhead of doing this currently exceeds the performance benefit so it is disabled. 

The JIT compiler takes this a step further with static compilation of the optimized micro-ops, the aim being to overcome the bottleneck and speed performance. It will not be enabled until several criteria are met, including at least 5 percent performance improvement, minimal disruption to deployment, and approval from the Python steering council. There are also possible security implications, and another downside is greater memory use at runtime.

Why include the feature if it is disabled by default? Currently “the JIT is about as fast as the existing specialized interpreter” so the 5 percent performance increase target has not yet been met; but even this, the authors of the feature state, is a “significant achievement, and it’s the main reason why the approach was considered viable enough to be merged into main for further development.” There are a number of improvements already under way, such that this is likely to be a future performance win.

Another key experiment in Python 3.13 is making the GIL optional, and therefore removing a major obstacle to concurrency. According to the PEP, “this lack of concurrency is often a bigger issue than speed of executing Python code.” Another advantage is that Python code will be better able to express parallelism, which has implications for making code more maintainable and will improve Python as a language for learning programming.

There is more in version 3.13, including a new interactive shell which colorized prompts, multiline editing with history preservation, and help browsing using the F1 key. This will only work though on Unix-like systems such as macOS and Linux. 

Apple’s IOS will now be a supported platform for Python, though only at Tier 3 (of three levels of support) and not including console or interactive use.

There are no new modules in 3.13, but many modules have improvements. Some modules will be newly deprecated, pending removal in version 3.14, 3.15 or 3.16.

The Python 3.13 release schedule features four beta releases and two release candidates, with final release set for early October 2024. Despite the feature-freeze, release manager Thomas Wouters states that “it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase.” This phase is set for the end of July.