This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [subinterpreters] Make the type attribute lookup cache per-interpreter
Type: Stage: resolved
Components: Interpreter Core, Subinterpreters Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2020-12-25 22:50 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23947 merged vstinner, 2020-12-25 23:35
PR 23953 merged vstinner, 2020-12-26 11:07
Messages (5)
msg383777 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-12-25 22:50
Currently, the type lookup cache is shared by all interpreter which causes multiple issues:

* The version tag is currently protected by the GIL, but it would require a new lock if the GIL is made per interpreter (bpo-40512)

* Clearing the cache in an interpreter clears the cache in all interpreters

* The cache has a fixed size of 4096 entries. The cache misses increase with the number of interpreters, since each interpreter has its own types.

I propose to make the type lookup cache per interpreter.
msg383786 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-12-26 00:45
New changeset 41010184880151d6ae02a226dbacc796e5c90d11 by Victor Stinner in branch 'master':
bpo-42745: Make the type cache per-interpreter (GH-23947)
https://github.com/python/cpython/commit/41010184880151d6ae02a226dbacc796e5c90d11
msg383816 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-12-26 18:08
41010184880151d6ae02a226dbacc796e5c90d11 introduced some reference leaks:

https://buildbot.python.org/all/#/builders/384/builds/136

41010184880151d6ae02a226dbacc796e5c90d11 is the first bad commit
commit 41010184880151d6ae02a226dbacc796e5c90d11
Author: Victor Stinner <vstinner@python.org>
Date:   Sat Dec 26 01:45:43 2020 +0100

    bpo-42745: Make the type cache per-interpreter (GH-23947)

    Make the type attribute lookup cache per-interpreter.

    Add private _PyType_InitCache() function, called by PyInterpreterState_New().

    Continue to share next_version_tag between interpreters, since static
    types are still shared by interpreters.

    Remove MCACHE macro: the cache is no longer disabled if the
    EXPERIMENTAL_ISOLATED_SUBINTERPRETERS macro is defined.

 Include/internal/pycore_interp.h                   |  22 +++
 Include/internal/pycore_object.h                   |   3 +
 Include/internal/pycore_pylifecycle.h              |   2 +-
 .../2020-12-25-23-30-58.bpo-42745.XsFoHS.rst       |   1 +
 Objects/typeobject.c                               | 178 ++++++++++++---------
 Python/pylifecycle.c                               |   2 +-
 Python/pystate.c                                   |   2 +
 7 files changed, 128 insertions(+), 82 deletions(-)
 create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-12-25-23-30-58.bpo-42745.XsFoHS.rst
bisect run success

I assume PR 23953 fixes those? If that is so, could we land it before more buildbots start to fail?
msg383820 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-12-26 19:04
> I assume PR 23953 fixes those?

Yes, it fix the 7 tests which leak:

./python -m test -R 3:3 -j0 test__xxsubinterpreters test_ast test_atexit test_capi test_interpreters test_threading
msg383822 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-12-26 19:26
New changeset f4507231e3f0cf8827cec5592571ce371c6813e8 by Victor Stinner in branch 'master':
bpo-42745: finalize_interp_types() calls _PyType_Fini() (GH-23953)
https://github.com/python/cpython/commit/f4507231e3f0cf8827cec5592571ce371c6813e8
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86911
2020-12-26 19:26:19vstinnersetmessages: + msg383822
2020-12-26 19:04:31vstinnersetmessages: + msg383820
2020-12-26 18:08:16pablogsalsetnosy: + pablogsal
messages: + msg383816
2020-12-26 11:07:51vstinnersetpull_requests: + pull_request22800
2020-12-26 00:46:02vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-26 00:45:46vstinnersetmessages: + msg383786
2020-12-25 23:35:58vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request22795
2020-12-25 23:22:40vstinnersettitle: [subinterpreters] Make the type lookup cache per-interpreter -> [subinterpreters] Make the type attribute lookup cache per-interpreter
2020-12-25 22:50:34vstinnercreate