diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-11-27 23:51:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-27 23:51:12 (GMT) |
commit | 4f71f1680de11baf7fb421ef500f36ffd5936b58 (patch) | |
tree | 425096370065266c1c762cd13bd0503b7a5952b4 /Include/internal/pycore_runtime_init.h | |
parent | 60a08e6ff2ef8306d276a40f861bf46f34ba09bd (diff) | |
download | cpython-4f71f1680de11baf7fb421ef500f36ffd5936b58.zip cpython-4f71f1680de11baf7fb421ef500f36ffd5936b58.tar.gz cpython-4f71f1680de11baf7fb421ef500f36ffd5936b58.tar.bz2 |
[3.12] gh-106931: Intern Statically Allocated Strings Globally (gh-107272) (gh-110713)
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.
(cherry-picked from commit b72947a8d26915156323ccfd04d273199ecb870c)
Diffstat (limited to 'Include/internal/pycore_runtime_init.h')
-rw-r--r-- | Include/internal/pycore_runtime_init.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 7aace9f..660d7d7 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -164,6 +164,7 @@ extern PyTypeObject _PyExc_MemoryError; .kind = 1, \ .compact = 1, \ .ascii = (ASCII), \ + .statically_allocated = 1, \ }, \ } #define _PyASCIIObject_INIT(LITERAL) \ |