Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In the free-threaded build, dictionary access hint specializations now attempt to enable deferred reference counting for resolved values owned by a different thread, reducing cross-thread reference count traffic and improving multi-threaded scalability.
Patch by Benedikt Johannes.
10 changes: 9 additions & 1 deletion Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,22 @@ specialize_dict_access_hint(
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_ATTR_SPLIT_DICT);
return 0;
}
Py_ssize_t index = _PyDict_LookupIndex(dict, name);
PyObject *value;
Py_ssize_t index = _PyDict_LookupIndexAndValue(dict, name, &value);
if (value != NULL && PyLazyImport_CheckExact(value)) {
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_ATTR_MODULE_LAZY_VALUE);
return 0;
}
if (index != (uint16_t)index) {
SPECIALIZATION_FAIL(base_op,
index == DKIX_EMPTY ?
SPEC_FAIL_ATTR_NOT_IN_DICT :
SPEC_FAIL_OUT_OF_RANGE);
return 0;
}
#ifdef Py_GIL_DISABLED
maybe_enable_deferred_ref_count(value);
#endif
cache->index = (uint16_t)index;
write_u32(cache->version, tp_version);
specialize(instr, hint_op);
Expand Down
Loading