![Welcome Python 3.11, an Upgrade to Counter Decades-Long Speed Issue](http://media.assettype.com/analyticsinsight%2Fimport%2Fwp-content%2Fuploads%2F2022%2F06%2FWelcome-Python-3.11-an-Upgrade-to-Counter-Decades-Long-Speed-Issue.jpg?w=480&auto=format%2Ccompress&fit=max)
Python is incredibly popular because it's easy to learn, versatile, and has thousands of useful libraries for data science. But one thing, it is not as fast. That's about to change in Python 3.11, currently in the first beta phase of its preview (version 3.11.0b1) ahead of its stable release later this year. It is one of the most keenly anticipated versions. "Python 3.11 is up to 10-60 percent faster than Python 3.10," state the release notes.
How is this being done? Python 3.11 is the first release to benefit from a project called Faster CPython, where CPython is the standard version of the interpreter. Faster CPython is a project funded by Microsoft, whose members include Python inventor Guido van Rossum, Microsoft senior software engineer Eric Snow, and Mark Shannon – who is under contract to Microsoft as tech lead for the project.
A session scheduled for the EuroPython event to be held in Dublin in July centers on some of the changes that enable the speed-up. Shannon will describe the "adaptive specializing interpreter" in Python 3.11, which is PEP (Python Enhancement Proposal) 659. This describes a technique called specialization which, Shannon explains, "is typically done in the context of a JIT [just in time] compiler, but research shows specialization in an interpreter can boost performance significantly."
The interpreter identifies code that can benefit from specialization and "once an instruction in a code object has executed enough times, that instruction will be "specialized" by replacing it with a new instruction that is expected to execute faster for that operation," states the PEP. The speed up can be "up to 50 percent."
Traceback (most recent call last):
File "distance.py", line 11, in
print(manhattan_distance(p1, p2))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "distance.py", line 6, in manhattan_distance
return abs(point_1.x – point_2.x) + abs(point_1.y – point_2.y)
^^^^^^^^^
Previous versions of the interpreter would point to just the line making it ambiguous which object was None. These enhanced errors can also be helpful when dealing with deeply nested dictionary objects and multiple function calls,
Traceback (most recent call last):
File "query.py", line 37, in
magic_arithmetic('foo')
^^^^^^^^^^^^^^^^^^^^^^^
File "query.py", line 18, in magic_arithmetic
return add_counts(x) / 25
^^^^^^^^^^^^^
File "query.py", line 24, in add_counts
return 25 + query_user(user1) + query_user(user2)
^^^^^^^^^^^^^^^^^
File "query.py", line 32, in query_user
return 1 + query_count(db, response['a']['b']['c']['user'], retry=True)
~~~~~~~~~~~~~~~~~~^^^^^
Traceback (most recent call last):
File "calculation.py", line 54, in
result = (x / y / z) * (a / b / c)
~~~~~~^~~
ZeroDivisionError: division by zero
PEP 654: Exception Groups and except*. (Contributed by Irit Katriel in bpo-45292.)
PEP 646: Variadic generics.
PEP 655: Marking individual TypedDict items as required or potentially missing.
PEP 673: Self type.
PEP 675: Arbitrary literal string type.
New -P command-line option and PYTHONSAFEPATH environment variable to not prepend a potentially unsafe path to sys.path such as the current directory, the script's directory or an empty string.
Many smaller improvements also landed in Python 3.11:
Join our WhatsApp Channel to get the latest news, exclusives and videos on WhatsApp
_____________
Disclaimer: Analytics Insight does not provide financial advice or guidance. Also note that the cryptocurrencies mentioned/listed on the website could potentially be scams, i.e. designed to induce you to invest financial resources that may be lost forever and not be recoverable once investments are made. You are responsible for conducting your own research (DYOR) before making any investments. Read more here.