diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-07-27 19:56:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 19:56:59 (GMT) |
commit | b72947a8d26915156323ccfd04d273199ecb870c (patch) | |
tree | ede8eba6e7824886303d482e746bbb92ea09e172 /Tools/build | |
parent | 4f67921ad28194155e3d4c16255fb140a6a4d89a (diff) | |
download | cpython-b72947a8d26915156323ccfd04d273199ecb870c.zip cpython-b72947a8d26915156323ccfd04d273199ecb870c.tar.gz cpython-b72947a8d26915156323ccfd04d273199ecb870c.tar.bz2 |
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.
Diffstat (limited to 'Tools/build')
-rw-r--r-- | Tools/build/deepfreeze.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Tools/build/deepfreeze.py b/Tools/build/deepfreeze.py index b084d3e..a11fe6a 100644 --- a/Tools/build/deepfreeze.py +++ b/Tools/build/deepfreeze.py @@ -208,6 +208,7 @@ class Printer: self.write(".kind = 1,") self.write(".compact = 1,") self.write(".ascii = 1,") + self.write(".statically_allocated = 1,") self.write(f"._data = {make_string_literal(s.encode('ascii'))},") return f"& {name}._ascii.ob_base" else: @@ -220,6 +221,7 @@ class Printer: self.write(f".kind = {kind},") self.write(".compact = 1,") self.write(".ascii = 0,") + self.write(".statically_allocated = 1,") utf8 = s.encode('utf-8') self.write(f'.utf8 = {make_string_literal(utf8)},') self.write(f'.utf8_length = {len(utf8)},') |