10000 gh-108362: Retarget incremental GC changes to 3.14 by hugovk · Pull Request #125453 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-108362: Retarget incremental GC changes to 3.14 #125453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into docs-3.14-increment…
…al-gc
  • Loading branch information
hugovk committed Apr 18, 2025
commit 93e4650f6b90be372748e5cf4c661e5fb14af796
175 changes: 175 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,127 @@ Improved error messages
^^^^^^^
ValueError: too many values to unpack (expected 3, got 4)

* If a statement (:keyword:`pass`, :keyword:`del`, :keyword:`return`,
:keyword:`yield`, :keyword:`raise`, :keyword:`break`, :keyword:`continue`,
:keyword:`assert`, :keyword:`import`, :keyword:`from`) is passed to the
:ref:`if_expr` after :keyword:`else`, or one of :keyword:`pass`,
:keyword:`break`, or :keyword:`continue` is passed before :keyword:`if`, then the
error message highlights where the :token:`~python-grammar:expression` is
required. (Contributed by Sergey Miryanov in :gh:`129515`.)

.. code-block:: pycon

>>> x = 1 if True else pass
Traceback (most recent call last):
File "<string>", line 1
x = 1 if True else pass
^^^^
SyntaxError: expected expression after 'else', but statement is given

>>> x = continue if True else break
Traceback (most recent call last):
File "<string>", line 1
x = continue if True else break
^^^^^^^^
SyntaxError: expected expression before 'if', but statement is given


* When incorrectly closed strings are detected, the error message suggests
that the string may be intended to be part of the string. (Contributed by
Pablo Galindo in :gh:`88535`.)

.. code-block:: python

>>> "The interesting object "The important object" is very important"
Traceback (most recent call last):
SyntaxError: invalid syntax. Is this intended to be part of the string?


.. _whatsnew314-pep741:

PEP 741: Python Configuration C API
-----------------------------------

Add a :ref:`PyInitConfig C API <pyinitconfig_api>` to configure the Python
initialization without relying on C structures and the ability to make
ABI-compatible changes in the future.

Complete the :pep:`587` :ref:`PyConfig C API <pyconfig_api>` by adding
:c:func:`PyInitConfig_AddModule` which can be used to add a built-in extension
module; feature previously referred to as the “inittab”.

Add :c:func:`PyConfig_Get` and :c:func:`PyConfig_Set` functions to get and set
the current runtime configuration.

PEP 587 “Python Initialization Configuration” unified all the ways to configure
the Python initialization. This PEP unifies also the configuration of the
Python preinitialization and the Python initialization in a single API.
Moreover, this PEP only provides a single choice to embed Python, instead of
having two “Python” and “Isolated” choices (PEP 587), to simplify the API
further.

The lower level PEP 587 PyConfig API remains available for use cases with an
intentionally higher level of coupling to CPython implementation details (such
as emulating the full functionality of CPython’s CLI, including its
configuration mechanisms).

(Contributed by Victor Stinner in :gh:`107954`.)

.. seealso::
:pep:`741`.

.. _whatsnew314-tail-call:

A new type of interpreter
-------------------------

A new type of interpreter has been added to CPython.
It uses tail calls between small C functions that implement individual
Python opcodes, rather than one large C case statement.
For certain newer compilers, this interpreter provides
significantly better performance. Preliminary numbers on our machines suggest
anywhere up to 30% faster Python code, and a geometric mean of 3-5%
faster on ``pyperformance`` depending on platform and architecture. The
baseline is Python 3.14 built with Clang 19 without this new interpreter.

This interpreter currently only works with Clang 19 and newer
on x86-64 and AArch64 architectures. However, we expect
that a future release of GCC will support this as well.

This feature is opt-in for now. We highly recommend enabling profile-guided
optimization with the new interpreter as it is the only configuration we have
tested and can validate its improved performance.
For further information on how to build Python, see
:option:`--with-tail-call-interp`.

.. note::

This is not to be confused with `tail call optimization`__ of Python
functions, which is currently not implemented in CPython.

This new interpreter type is an internal implementation detail of the CPython
interpreter. It doesn't change the visible behavior of Python programs at
all. It can improve their performance, but doesn't change anything else.

__ https://en.wikipedia.org/wiki/Tail_call

.. attention::

This section previously reported a 9-15% geometric mean speedup. This number has since been
cautiously revised down to 3-5%. While we expect performance results to be better
than what we report, our estimates are more conservative due to a
`compiler bug <https://github.com/llvm/llvm-project/issues/106846>`_ found in
Clang/LLVM 19, which causes the normal interpreter to be slower. We were unaware of this bug,
resulting in inaccurate results. We sincerely apologize for
communicating results that were only accurate for LLVM v19.1.x and v20.1.0. In the meantime,
the bug has been fixed in LLVM v20.1.1 and for the upcoming v21.1, but it will remain
unfixed for LLVM v19.1.x and v20.1.0. Thus
any benchmarks with those versions of LLVM may produce inaccurate numbers.
(Thanks to Nelson Elhage for bringing this to light.)

(Contributed by Ken Jin in :gh:`128563`, with ideas on how to implement this
in CPython by Mark Shannon, Garrett Gu, Haoran Xu, and Josh Haberman.)


.. _whatsnew314-incremental-gc:

Expand All @@ -301,6 +422,7 @@ The behavior of :func:`!gc.collect` changes slightly:

(Contributed by Mark Shannon in :gh:`108362`.)


Other language changes
======================

Expand Down Expand Up @@ -1240,6 +1362,21 @@ asyncio
reduces memory usage.
(Contributed by Kumar Aditya in :gh:`107803`.)

* :mod:`asyncio` has new utility functions for introspecting and printing
the program's call graph: :func:`asyncio.capture_call_graph` and
:func:`asyncio.print_call_graph`.
(Contributed by Yury Selivanov, Pablo Galindo Salgado, and Łukasz Langa
in :gh:`91048`.)


base64
------

* Improve the performance of :func:`base64.b16decode` by up to ten times,
and reduce the import time of :mod:`base64` by up to six times.
(Contributed by Bénédikt Tran, Chris Markiewicz, and Adam Turner in :gh:`118761`.)


gc
--

Expand All @@ -1248,6 +1385,44 @@ gc
by an order of magnitude or more for larger heaps.
(Contributed by Mark Shannon in :gh:`108362`.)


io
---
* :mod:`io` which provides the built-in :func:`open` makes less system calls
when opening regular files as well as reading whole files. Reading a small
operating system cached file in full is up to 15% faster.
:func:`pathlib.Path.read_bytes` has the most optimizations for reading a
file's bytes in full. (Contributed by Cody Maloney and Victor Stinner in
:gh:`120754` and :gh:`90102`.)


uuid
----

* Improve generation of :class:`~uuid.UUID` objects via their dedicated
functions:

* :func:`~uuid.uuid3` and :func:`~uuid.uuid5` are both roughly 40% faster
for 16-byte names and 20% faster for 1024-byte names. Performance for
longer names remains unchanged.
* :func:`~uuid.uuid4` and :func:`~uuid.uuid8` are 30% and 40% faster
respectively.

(Contributed by Bénédikt Tran in :gh:`128150`.)


zlib
----

* On Windows, ``zlib-ng`` is now used as the implementation of the
:mod:`zlib` module. This should produce compatible and comparable
results with better performance, though it is worth noting that
``zlib.Z_BEST_SPEED`` (1) may result in significantly less
compression than the previous implementation (while also significantly
reducing the time taken to compress).
(Contributed by Steve Dower in :gh:`91349`.)


Deprecated
==========

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0