Programming languages: Python is slow, but it’s about to get faster

Python is incredibly popular because it is easy to learn, versatile and has thousands of useful libraries for data science. But the only thing was it wasn’t fast.

This is about to change in Python 3.11, currently in the first beta phase of preview (version 3.11.0b1) ahead of its stable release later this year. Core Python developer (CPython) Mark Shannon has shared details about the project to make Python faster in PyCon 2022 this weekWhere developers also Show the progress of the goal of running Python code in the browser.

Last year, Microsoft funded a project for the Python Software Foundation (PSF), led by Python creator Guido van Rossum and Shannon, To make Python twice as fast As a stable current 3.10 series. The vision is to drive Python toward C performance.

be seen: How to Get a Promotion: Five Ways to Climb the Ladder and Have a Successful Career

Microsoft Hired Van Rossum in 2020 And give him the freedom to choose any project. At PyCon 2021 last year, he said he had “chosen to go back to my roots” and would work on Python’s notorious lack of performance.

Performance may not have been a top priority for Python as adoption has been boosted by machine learning and data science thanks to Tensor Flow, Numpy, Pandas and Many other platforms, such as the Boto3 SDK for Python from AWS. These platforms are downloaded tens of millions of times per month and used in environments that are often not limited by hardware.

Fastest CPython project Submitted Some updates about CPython 3.11 performance over the past year. Before PyCon 2022, the project published more Results comparing Preview 3.11 beta to 3.10 on dozens of performance measures, showing that 3.11 was 1.25 times faster overall than 3.10.

Shannon is realistic about the project’s ability to improve Python’s performance, but believes that the improvements can extend the viable use of Python to more virtual machines.

“Python is widely acknowledged to be slow. While Python will never achieve the performance of low-level languages ​​like C, Fortran, or even Java, we would like it to be competitive with fast implementations of scripting languages, such as V8 for Javascript or luajit.” for Lua” he wrote Last year in Python Improvement Proposal (PEP) 659.

“Specifically, we want to achieve these performance goals using CPython to benefit all Python users including those unable to use PyPy or other alternative virtual machines.”

The main approach detailed in PEP 659 is “a specialized and adaptable compiler that specializes in code aggressively, but in a very small area, and is able to adapt to poor specialization quickly and inexpensively.”

As noted, virtual machine optimizations are “expensive”, and often require a long “warm-up” time. To avoid this time expense, the VM must “speculate that specialization is justified even after only a few functions are implemented”, so the interpreter needs to optimize and de-optimize constantly and very inexpensively.

This should result in a faster CPython compiler that keeps track of individual byte codes during program execution. Work on the new interpreter is almost complete but still requires the completion of the dynamic disciplines of loops and binary operations, According to PSF.

In addition, memory consumption has not changed in 3.11 from 3.10.

be seen: Developers are facing burnout. Here’s how companies are trying to fix it

On the issue of the just-in-time (JIT) compiler for Python performance, Shannon suggested that it wasn’t a priority and likely won’t reach Python 3.13, according to the Python Software Foundation’s coverage of the event.

Anaconda, Anaconda Python Distribution Maker for Data Science, Supports the piston projecta Python app that promises speed improvements over Python.

One of Anaconda’s early efforts to speed up Python was Project Numba, an LLVM-based JIT compiler for CPython, which accelerates numeric Python functions running on a CPU or GPU, but cannot optimize programs entirely and does not address broader Python use cases . else PyPyCPython app with JIT interpreter for faster performance.

According to the implementation plan of Faster PythonCPython 3.12 may get a “simple JIT compiler for small areas” that compiles small areas of specialized code, while 3.13 will enhance the compiler to extend the assembly areas.