Python 3.13: more performance without GIL

0
10
Python 3.13: more performance without GIL


iX Workshop: OWASP® Top 10 – Understanding Security Risks for Web ApplicationsiX Workshop: OWASP® Top 10 – Understanding Security Risks for Web Applications

Python is known for its simplicity and versatility, but not for its outstanding speed. For many versions, a dedicated team is working specifically on execution performance; Version 3.13 shows the first results: a just-in-time compiler (JIT) and real multithreading (free threading). Both approaches form the basis for further optimization, but already bring interesting improvements.

Unlike languages ​​like C or Rust, where ahead-of-time (AOT) compilers compile the code, dynamic languages ​​like Python are only translated into machine code at runtime. Some optimizations are made when the program starts so that there is not too much delay in the start time. JIT compilers try to combine fast start, dynamicity, and fast execution. Newer Python versions have now integrated this technology, which is already established in many other programming languages ​​– but with one important difference.

  • Python 3.13 has a JIT compiler that uses a copy-and-patch method for fast and efficient code optimization: specific values ​​are inserted into pre-built machine code templates at runtime.
  • There is also a version without the Global Interpreter Lock (GIL): this enables true multithreading support and greater performance when a script uses multiple cores.
  • While the performance gain from the JIT compiler is currently manageable, the gain from free threading is already greater, but still creates incompatibilities.

Classic JIT compilers, for example, are based on LLVM or specially programmed tools. They identify hotspots during code execution, i.e. parts of the code that are run particularly frequently. Once the threshold value is reached, they mark the previous code for optimization. This selective optimization costs some CPU time and memory, but the optimized code should result in better overall execution performance.

This was a reading sample from our Heise Plus article “Python 3.13: More performance without the GIL”. With a Heise Plus subscription you can read and listen to the full article.


Cryptocurrency: Ethereum developers are targeted by attackersCryptocurrency: Ethereum developers are targeted by attackers

LEAVE A REPLY

Please enter your comment!
Please enter your name here