FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.12] gh-106931: Intern Statically Allocated Strings Globally (gh-107272) by ericsnowcurrently · Pull Request #110713 · python/cpython · GitHub

/ cpython Public

[3.12] gh-106931: Intern Statically Allocated Strings Globally (gh-107272) - #110713

Merged
ericsnowcurrently merged 7 commits into
python:3.12from
ericsnowcurrently:backport-b72947a-fix-interned-strings
Nov 27, 2023
Merged

[3.12] gh-106931: Intern Statically Allocated Strings Globally (gh-107272)#110713
ericsnowcurrently merged 7 commits into
python:3.12from
ericsnowcurrently:backport-b72947a-fix-interned-strings

Conversation

ericsnowcurrently commented Oct 11, 2023
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

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 b72947a)

(This supersedes gh-107358.)

…ythongh-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.

(cherry-picked from commit b72947a)
Comment thread Include/internal/pycore_runtime.h Outdated
ericsnowcurrently enabled auto-merge (squash) November 27, 2023 23:25
ericsnowcurrently merged commit 4f71f16 into python:3.12 Nov 27, 2023
ericsnowcurrently deleted the backport-b72947a-fix-interned-strings branch November 27, 2023 23:57

Copy link
Copy Markdown
Member

This broke the 3.12 WASI build: https://buildbot.python.org/all/#/builders/1124/builds/464/steps/11/logs/stdio .

Opened #112503 to track the fix (which is backporting a change made on main).

ericsnowcurrently added a commit that referenced this pull request Nov 29, 2023
Skip tests if no interpreters module.gh-110713 added some tests that use the interpreters module but did not accommodated builds that don't support subinterpreters (incl. an interpreters module).  We fix that here by catching ImportError and skipping tests as appropriate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL