8000 bpo-47189: What's New in 3.11: Faster CPython by Fidget-Spinner · Pull Request #32235 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-47189: What's New in 3.11: Faster CPython #32235

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 20 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Add section on static code objects/freezing imports
Co-Authored-By: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
  • Loading branch information
Fidget-Spinner and kumaraditya303 committed Mar 25, 2022
commit 77701feba07ed673948bdfe8c64d8c5a44444540
2 changes: 2 additions & 0 deletions Doc/tutorial/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ directory. This is an error unless the replacement is intended. See section
.. %
Do we need stuff on zip files etc. ? DUBOIS

.. _tut-pycache:

"Compiled" Python files
-----------------------

Expand Down
26 changes: 22 additions & 4 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,29 @@ runtime. Other optimizations not under this project are listed in `Optimizations
Faster Startup
--------------

Static objects
~~~~~~~~~~~~~~
Frozen imports / Static code objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Freezing imports
~~~~~~~~~~~~~~~~
Python caches bytecode in the :ref:`__pycache__<tut-pycache>` directory to
speed up module loading.

Previously in 3.10, Python module execution looked like this:

.. code-block:: text

Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate

In Python 3.11, the core modules essential for Python startup are "frozen".
This means that their code objects (and bytecode) are statically allocated
by the interpreter. This reduces the steps in module execution process to this:

.. code-block:: text

Statically allocated code object -> Evaluate

Interpreter startup is now 10-15% faster in Python 3.11.

(Contributed by Eric Snow, Guido van Rossum and Kumar Aditya in numerous issues.)


Faster Runtime
Expand Down
0