-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
[3.12] gh-106931: Intern Statically Allocated Strings Globally (gh-107272) #110713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ericsnowcurrently
merged 7 commits into
python:3.12
from
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.12
from
ericsnowcurrently:backport-b72947a-fix-interned-strings
Nov 27, 2023
Conversation
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
…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)
This was referenced Oct 11, 2023
352cfd9
to
4e60828
Compare
Yhg1s
reviewed
Nov 20, 2023
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 |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.)