gh-115999: Specialize LOAD_GLOBAL in free-threaded builds#126607
Merged
mpage merged 19 commits intopython:mainpython/cpython:mainfrom Nov 21, 2024
mpage:gh-115999-tlbc-load-globalmpage/cpython:gh-115999-tlbc-load-globalCopy head branch name to clipboard
Merged
gh-115999: Specialize LOAD_GLOBAL in free-threaded builds#126607mpage merged 19 commits intopython:mainpython/cpython:mainfrom mpage:gh-115999-tlbc-load-globalmpage/cpython:gh-115999-tlbc-load-globalCopy head branch name to clipboard
LOAD_GLOBAL in free-threaded builds#126607mpage merged 19 commits intopython:mainpython/cpython:mainfrom
mpage:gh-115999-tlbc-load-globalmpage/cpython:gh-115999-tlbc-load-globalCopy head branch name to clipboard
Conversation
Thread-safety of specialization in free-threaded builds: - A critical section is held on both the globals and builtins objects during specialization. This ensures we get an atomic view of both builtins and globals during specialization. - Generation of new keys versions is made atomic in free-threaded builds. - We use helpers safely modify the bytecode. Thread-safety of specialized instructions in free-threaded builds: - Dicts keys objects are passed from keys version guards to the downstream uops. This ensures that we are loading from the correct offset in the keys object. Once a unicode key has been stored in a keys object for a combined dictionary in free-threaded builds, the offset that it is stored in will never be reaused for a different key. - The dictionary read fast-path is used to read values from the dictionary. - Relaxed atomics are used when loading and storing dict keys versions. This avoids potential data races as the dict keys versions may be read without holding the dictionary's per-object lock while the instructions are executing.
This handles the case where another thread is instrumenting the bytecode.
Member
Fidget-Spinner
left a comment
There was a problem hiding this comment.
This was less complicated than I initially anticipated. Nice!
LGTM overall, but I'll withold from approval to let others review it first.
colesbury
reviewed
Nov 11, 2024
Contributor
colesbury
left a comment
There was a problem hiding this comment.
Nice! A few comments below.
Keys are freed using QSBR. Nothing occurs in between loading the keys and loading the value that would cause the QSBR version to advance, ensuring that the keys object cannot be freed and reused.
colesbury
reviewed
Nov 19, 2024
colesbury
approved these changes
Nov 19, 2024
Contributor
Author
|
!buildbot nogil refleak |
|
🤖 New build scheduled with the buildbot fleet by @mpage for commit 01f4143 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
ebonnal
pushed a commit
to ebonnal/cpython
that referenced
this pull request
Jan 12, 2025
…thon#126607) Enable specialization of LOAD_GLOBAL in free-threaded builds. Thread-safety of specialization in free-threaded builds is provided by the following: A critical section is held on both the globals and builtins objects during specialization. This ensures we get an atomic view of both builtins and globals during specialization. Generation of new keys versions is made atomic in free-threaded builds. Existing helpers are used to atomically modify the opcode. Thread-safety of specialized instructions in free-threaded builds is provided by the following: Relaxed atomics are used when loading and storing dict keys versions. This avoids potential data races as the dict keys versions are read without holding the dictionary's per-object lock in version guards. Dicts keys objects are passed from keys version guards to the downstream uops. This ensures that we are loading from the correct offset in the keys object. Once a unicode key has been stored in a keys object for a combined dictionary in free-threaded builds, the offset that it is stored in will never be reused for a different key. Once the version guard passes, we know that we are reading from the correct offset. The dictionary read fast-path is used to read values from the dictionary once we know the correct offset.
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
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.
Enable specialization of
LOAD_GLOBALin free-threaded builds.Thread-safety of specialization in free-threaded builds is provided by the following:
Thread-safety of specialized instructions in free-threaded builds is provided by the following:
Performance-wise, this looks like a 3-4% improvement on free-threaded builds on pyperformance.
--disable-gilbuilds #115999