-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
gh-130373: Avoid locking in _LOAD_ATTR_WITH_HINT #130372
base: main
Are you sure you want to change the base?
Conversation
Python/bytecodes.c
Outdated
POP_INPUT(dict); | ||
DEOPT_IF(true); | ||
} | ||
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint; | ||
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dk) + hint; | ||
if (ep->me_key != name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the read of ep->me_key
needs to be atomic (can be relaxed).
Python/bytecodes.c
Outdated
} else if (dk != FT_ATOMIC_LOAD_PTR(dict->ma_keys)) { | ||
PyStackRef_CLOSE(attr); | ||
POP_INPUT(dict); | ||
DEOPT_IF(true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this check dk != FT_ATOMIC_LOAD_PTR(dict->ma_keys)
. Even if the dict->ma_keys
changed, we should still have loaded a valid previous value at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems right to me, I think that means we also don't need the check here? https://github.com/python/cpython/blob/main/Objects/dictobject.c#L1527
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. There's also a similar check a few lines below that in the same function:
Lines 1547 to 1550 in 69426fc
if (dk != _Py_atomic_load_ptr(&mp->ma_keys)) { | |
Py_DECREF(value); | |
goto read_failed; | |
} |
@@ -2286,38 +2286,40 @@ dummy_func( | |||
} | |||
|
|||
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner, dict: PyDictObject * -- attr)) { | |||
PyDictKeysObject *dk = FT_ATOMIC_LOAD_PTR(dict->ma_keys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we need to check the equivalent of ensure_shared_on_read
either here or in _CHECK_ATTR_WITH_HINT
.
163dd7b
to
6f8b1d7
Compare
6f8b1d7
to
15c28cb
Compare
Adds a lock-free lookup of the hinted location
https://github.com/facebookexperimental/free-threading-benchmarking/tree/main/results/bm-20250219-3.14.0a5+-6a1fe7e-NOGIL