January 27, 2023


Networking, PBX, IT, DIY Solution

When will the extremely popular Python get faster?

4 min read

When will the extremely popular Python get faster?

When will the extremely popular Python get faster?

As an extremely popular programming language, Python has many advantages, such as: easy to learn, versatile, and has thousands of useful libraries for data science.

But at the same time, Python has been criticized for being too slow.

At last year’s PyCon US 2021 conference, the father of Python said: In Python 3.11 in 2022, the speed of Python will be increased by 2 times, and within 4 years, the speed will be increased by 5 times, so as to solve the problem of comparing Python with other programming languages ​​such as C++ The key disadvantage in speed.

Today, too slow is about to change in Python 3.11. It is currently in the first beta phase of its preview release (version 3.11.0b1) before a stable release later this year.

CPython 3.11 is 1.25 times faster than 3.10

At the recent PyCon US 2022 conference, Core Python (CPython) developer Mark Shannon shared details on accelerating Python projects, and the developers also showed progress towards the goal of running Python code in the browser .

Last year, Microsoft funded a Python Software Foundation (PSF) project, the “Shannon Plan,” led by Python creators Guido van Rossum and Mark Shannon, which promised to make it 2x faster in this year’s Python 3.11 . Its vision is to push Python towards the performance of C.

When will the extremely popular Python get faster?

Microsoft hired van Rossum in 2020 and gave him the freedom to choose any project. At last year’s PyCon US 2021 conference, he said he “chooses to go back to my roots” and will work on addressing Python’s famous performance deficit

Performance may not be the top priority for Python, as machine learning and data science adoption benefits from TensorFlow, NumPy, Pandas, and more platforms like AWS’ Boto3 SDK for Python. These platforms are downloaded tens of millions of times a month and used in environments that are often not limited by hardware.

The Faster CPython project (GitHub address: ideas/main-vs-310.rst at main · faster-cpython/ideas · GitHub ) provides some performance updates about CPython 3.11 over the past year. Ahead of the PyCon US 2022 conference, the project announced more results: a comparison of the 3.11 beta preview and 3.10 on dozens of performance metrics showed that 3.11.0b1 was 1.25 times faster than 3.10 overall .

New bytecode interpreter makes error handling more efficient

Shannon is realistic about the project’s ability to improve Python performance, but he believes the improvements could expand Python’s viable uses to more virtual machines.

He wrote in Python Enhancement Proposal (PEP) 659 last year : “Python is widely considered to be slow. While Python will never match the performance of lower-level languages ​​like C, Fortran, or even Java, we hope it will match the speed of scripting languages. Implementations are comparable to those of Javascript’s V8 or Lua’s LuaJIT.

Specifically, we hope to achieve these performance goals with CPython to the benefit of all Python users, including those who cannot use PyPy or other alternative virtual machines.”

The key approach detailed in PEP 659 is: “A specialized, adaptive interpreter, but which aggressively specializes code in a very small area and is able to quickly and inexpensively accommodate faulty specializations. “

As mentioned above, optimization of virtual machines is “expensive” and often requires a long “warm-up” time. To avoid this time overhead, the virtual machine should speculate that “specialization is reasonable even after a function has been executed several times”.

Therefore, the interpreter needs to be optimized and de-optimized continuously and very cheaply.

This should result in a faster CPython interpreter that can trace individual bytecodes during program execution.

According to the Python Software Foundation (PSF) , work on the new interpreter is almost complete, but dynamic specialization of loops and binary operations still needs to be done.

Also, the memory consumption of 3.11 has not changed compared to 3.10.

CPython JIT compiler coming soon

Regarding the issue of just-in-time (JIT) compilers for Python performance, according to the Python Software Foundation (PSF) reporting on the event, Shannon believes that this is not a priority and may not be implemented until Python 3.13 at the earliest.

Additionally, Anaconda, maker of the Anaconda Python distribution for data science, is supporting the Pyston project, an implementation of Python that promises speed improvements over Python.

One of Anaconda’s earlier efforts to speed up Python was the Numba project, an LLVM-based CPython JIT compiler that accelerated Python numerical functions running on CPUs or GPUs, but did not optimize entire programs or solve more complex problems.

Extensive Python use cases. The other is PyPy, which is an implementation of CPython with a JIT compiler for faster performance.

According to the implementation plan of the Faster CPython project (GitHub address: faster-cpython/plan.md at master · markshannon/faster-cpython · GitHub ), CPython 3.12 may get a “simple JIT compiler for small areas”, which will run CPython 3.13 will expand the compilation area and enhance the compiler to generate superior machine code.

Finally, what do you think of the above Faster CPython project’s approach to speeding up Python? 

Copyright © All rights reserved. | Newsphere by AF themes.