From 3c8f2a3144adf648ace5eb2019bb2ad9882d164d Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Tue, 18 Oct 2022 19:41:06 -0500 Subject: [PATCH 1/6] Edit and xref Optimizations section --- Doc/whatsnew/3.11.rst | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 79afc1f99e99d9..6fee177bed384a 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1128,26 +1128,28 @@ fcntl Optimizations ============= -* Compiler now optimizes simple C-style formatting with literal format - containing only format codes ``%s``, ``%r`` and ``%a`` and makes it as - fast as corresponding f-string expression. +* The compiler now optimizes simple + :ref:`printf-style % 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`.) -* "Zero-cost" exceptions are implemented. The cost of ``try`` statements is - almost eliminated when no exception is raised. +* "Zero-cost" exceptions are implemented, eliminating the cost + of :keyword:`try` statements when no exception is raised. (Contributed by Mark Shannon in :issue:`40222`.) -* Pure ASCII strings are now normalized in constant time by :func:`unicodedata.normalize`. +* Pure ASCII strings are now normalized in constant time by + :func:`unicodedata.normalize`. (Contributed by Dong-hee Na in :issue:`44987`.) -* :mod:`math` functions :func:`~math.comb` and :func:`~math.perm` are now up - to 10 times or more faster for large arguments (the speed up is larger for - larger *k*). +* :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`.) -* Dict don't store hash value when all inserted keys are Unicode objects. - This reduces dict size. For example, ``sys.getsizeof(dict.fromkeys("abcdefg"))`` - becomes 272 bytes from 352 bytes on 64bit platform. +* Dictionaries don't store hash values when all keys are Unicode objects, + decreasing :class:`dict` size. + 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`.) * :mod:`re`'s regular expression matching engine has been partially refactored, From 3d5f4c4260e0e90acf9279ba8d573eaabd20308f Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Tue, 18 Oct 2022 19:59:16 -0500 Subject: [PATCH 2/6] Re-order by language (impact), builtins (impact), stdlib (a->z) --- Doc/whatsnew/3.11.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 6fee177bed384a..6c9855a820cfc1 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1128,36 +1128,36 @@ fcntl Optimizations ============= +* "Zero-cost" exceptions are implemented, eliminating the cost + of :keyword:`try` statements when no exception is raised. + (Contributed by Mark Shannon in :issue:`40222`.) + * The compiler now optimizes simple :ref:`printf-style % 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`.) -* "Zero-cost" exceptions are implemented, eliminating the cost - of :keyword:`try` statements when no exception is raised. - (Contributed by Mark Shannon in :issue:`40222`.) - -* Pure ASCII strings are now normalized in constant time by - :func:`unicodedata.normalize`. - (Contributed by Dong-hee Na in :issue:`44987`.) - -* :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`.) - * Dictionaries don't store hash values when all keys are Unicode objects, decreasing :class:`dict` size. 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`.) +* :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`.) + * :mod:`re`'s regular expression matching engine has been partially refactored, and now uses computed gotos (or "threaded code") on supported platforms. As a result, Python 3.11 executes the `pyperformance regular expression benchmarks `_ up to 10% faster than Python 3.10. +* :func:`unicodedata.normalize` + now normalizes pure-ASCII strings in constant time. + (Contributed by Dong-hee Na in :issue:`44987`.) + .. _whatsnew311-faster-cpython: From c99b5079952a5a8fc4aa2860f0f7f64f93919ba3 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Tue, 18 Oct 2022 21:14:07 -0500 Subject: [PATCH 3/6] Add additional significant optimizations mentioned in the changelog --- Doc/whatsnew/3.11.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 6c9855a820cfc1..46170d32149bdf 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1138,12 +1138,30 @@ Optimizations fast as a corresponding :term:`f-string` expression. (Contributed by Serhiy Storchaka in :issue:`28307`.) +* Integer division (``//``) is better tuned for optimization by compilers. + It is now around 20% faster on x86-64 when dividing an :class:`int` + by a value smaller than ``2**30``. + (Contributed by Gregory P. Smith and Tim Peters in :gh:`90564`.) + +* :func:`sum` is now nearly 30% faster for integers smaller than ``2**30``. + (Contributed by Stefan Behnel in :gh:`68264`.) + +* Resizing lists is streamlined for the common case, + speeding up :meth:`list.append` by ≈15% + and simple :term:`list comprehension`\s by up to 20-30% + (Contributed by Dennis Sweeney in :gh:`91165`.) + * Dictionaries don't store hash values when all keys are Unicode objects, decreasing :class:`dict` size. 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`.) +* Using :class:`asyncio.DatagramProtocol` is now orders of magnitude faster + when transferring large files over UDP, + with speeds over 100 times higher for a ≈60 MiB file. + (Contributed by msoxzw in :gh:`91487`.) + * :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`.) @@ -1154,6 +1172,12 @@ Optimizations `_ up to 10% faster than Python 3.10. +* 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`.) From 6d1c18234e5a614e4461fb46071c9536caa6883b Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Tue, 18 Oct 2022 21:51:57 -0500 Subject: [PATCH 4/6] Add intro clarifying scope and linking to Faster CPython section --- Doc/whatsnew/3.11.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 46170d32149bdf..25e126d5ca7882 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1128,6 +1128,9 @@ fcntl Optimizations ============= +This section covers specific optimizations independent of the +:ref:`whatsnew311-faster-cpython` project, which is covered in its own section. + * "Zero-cost" exceptions are implemented, eliminating the cost of :keyword:`try` statements when no exception is raised. (Contributed by Mark Shannon in :issue:`40222`.) From e7a1a01b00d004c887e65777132bb46e3cf772d5 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Wed, 19 Oct 2022 14:35:02 -0500 Subject: [PATCH 5/6] Remove gh-91404 re entry from Optimizations to add to Faster CPython --- Doc/whatsnew/3.11.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 25e126d5ca7882..07ee5a16fa64b8 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1169,12 +1169,6 @@ This section covers specific optimizations independent of the ≈10 times faster for large arguments (with a larger speedup for larger *k*). (Contributed by Serhiy Storchaka in :issue:`37295`.) -* :mod:`re`'s regular expression matching engine has been partially refactored, - and now uses computed gotos (or "threaded code") on supported platforms. As a - result, Python 3.11 executes the `pyperformance regular expression benchmarks - `_ up to 10% - faster than Python 3.10. - * 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. From 5dc44490ad2edf6fd67c668223d4facafa0c27b1 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 20 Oct 2022 13:25:58 -0500 Subject: [PATCH 6/6] Remove zero-cost exceptions from Optimization to move to Faster CPython --- Doc/whatsnew/3.11.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 07ee5a16fa64b8..fe50e188933457 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1131,10 +1131,6 @@ Optimizations This section covers specific optimizations independent of the :ref:`whatsnew311-faster-cpython` project, which is covered in its own section. -* "Zero-cost" exceptions are implemented, eliminating the cost - of :keyword:`try` statements when no exception is raised. - (Contributed by Mark Shannon in :issue:`40222`.) - * The compiler now optimizes simple :ref:`printf-style % formatting ` on string literals containing only the format codes ``%s``, ``%r`` and ``%a`` and makes it as