gh-95913: Edit & expand Optimizations in 3.11 WhatsNew (#98426)

This commit is contained in:
C.A.M. Gerlach 2022-10-22 14:14:11 -05:00 committed by GitHub
parent 8f30267ab4
commit f58631be11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1171,33 +1171,52 @@ fcntl
Optimizations Optimizations
============= =============
* Compiler now optimizes simple C-style formatting with literal format This section covers specific optimizations independent of the
containing only format codes ``%s``, ``%r`` and ``%a`` and makes it as :ref:`whatsnew311-faster-cpython` project, which is covered in its own section.
fast as corresponding f-string expression.
* The compiler now optimizes simple
:ref:`printf-style % formatting <old-string-formatting>` on string literals
containing only the format codes ``%s``, ``%r`` and ``%a`` and makes it as
fast as a corresponding :term:`f-string` expression.
(Contributed by Serhiy Storchaka in :issue:`28307`.) (Contributed by Serhiy Storchaka in :issue:`28307`.)
* "Zero-cost" exceptions are implemented. The cost of ``try`` statements is * Integer division (``//``) is better tuned for optimization by compilers.
almost eliminated when no exception is raised. It is now around 20% faster on x86-64 when dividing an :class:`int`
(Contributed by Mark Shannon in :issue:`40222`.) by a value smaller than ``2**30``.
(Contributed by Gregory P. Smith and Tim Peters in :gh:`90564`.)
* Pure ASCII strings are now normalized in constant time by :func:`unicodedata.normalize`. * :func:`sum` is now nearly 30% faster for integers smaller than ``2**30``.
(Contributed by Dong-hee Na in :issue:`44987`.) (Contributed by Stefan Behnel in :gh:`68264`.)
* :mod:`math` functions :func:`~math.comb` and :func:`~math.perm` are now up * Resizing lists is streamlined for the common case,
to 10 times or more faster for large arguments (the speed up is larger for speeding up :meth:`list.append` by ≈15%
larger *k*). and simple :term:`list comprehension`\s by up to 20-30%
(Contributed by Serhiy Storchaka in :issue:`37295`.) (Contributed by Dennis Sweeney in :gh:`91165`.)
* Dict don't store hash value when all inserted keys are Unicode objects. * Dictionaries don't store hash values when all keys are Unicode objects,
This reduces dict size. For example, ``sys.getsizeof(dict.fromkeys("abcdefg"))`` decreasing :class:`dict` size.
becomes 272 bytes from 352 bytes on 64bit platform. For example, ``sys.getsizeof(dict.fromkeys("abcdefg"))``
is reduced from 352 bytes to 272 bytes (23% smaller) on 64-bit platforms.
(Contributed by Inada Naoki in :issue:`46845`.) (Contributed by Inada Naoki in :issue:`46845`.)
* :mod:`re`'s regular expression matching engine has been partially refactored, * Using :class:`asyncio.DatagramProtocol` is now orders of magnitude faster
and now uses computed gotos (or "threaded code") on supported platforms. As a when transferring large files over UDP,
result, Python 3.11 executes the `pyperformance regular expression benchmarks with speeds over 100 times higher for a ≈60 MiB file.
<https://pyperformance.readthedocs.io/benchmarks.html#regex-dna>`_ up to 10% (Contributed by msoxzw in :gh:`91487`.)
faster than Python 3.10.
* :mod:`math` functions :func:`~math.comb` and :func:`~math.perm` are now
≈10 times faster for large arguments (with a larger speedup for larger *k*).
(Contributed by Serhiy Storchaka in :issue:`37295`.)
* The :mod:`statistics` functions :func:`~statistics.mean`,
:func:`~statistics.variance` and :func:`~statistics.stdev` now consume
iterators in one pass rather than converting them to a :class:`list` first.
This is twice as fast and can save substantial memory.
(Contributed by Raymond Hettinger in :gh:`90415`.)
* :func:`unicodedata.normalize`
now normalizes pure-ASCII strings in constant time.
(Contributed by Dong-hee Na in :issue:`44987`.)
.. _whatsnew311-faster-cpython: .. _whatsnew311-faster-cpython: