]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-106931: Intern Statically Allocated Strings Globally (gh-107272)
authorEric Snow <ericsnowcurrently@gmail.com>
Thu, 27 Jul 2023 19:56:59 +0000 (13:56 -0600)
committerGitHub <noreply@github.com>
Thu, 27 Jul 2023 19:56:59 +0000 (13:56 -0600)
commitb72947a8d26915156323ccfd04d273199ecb870c
treeede8eba6e7824886303d482e746bbb92ea09e172
parent4f67921ad28194155e3d4c16255fb140a6a4d89a
gh-106931: Intern Statically Allocated Strings Globally (gh-107272)

We tried this before with a dict and for all interned strings.  That ran into problems due to interpreter isolation.  However, exclusively using a per-interpreter cache caused some inconsistency that can eliminate the benefit of interning.  Here we circle back to using a global cache, but only for statically allocated strings.  We also use a more-basic _Py_hashtable_t for that global cache instead of a dict.

Ideally we would only have the global cache, but the optional isolation of each interpreter's allocator means that a non-static string object must not outlive its interpreter.  Thus we would have to store a copy of each such interned string in the global cache, tied to the main interpreter.
Include/cpython/unicodeobject.h
Include/internal/pycore_global_objects.h
Include/internal/pycore_hashtable.h
Include/internal/pycore_runtime.h
Include/internal/pycore_runtime_init.h
Lib/test/test_sys.py
Misc/NEWS.d/next/Core and Builtins/2023-07-25-15-29-26.gh-issue-106931.kKU1le.rst [new file with mode: 0644]
Objects/unicodeobject.c
Python/hashtable.c
Tools/build/deepfreeze.py