-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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-124218: Avoid refcount contention on builtins module #125847
Conversation
This replaces `_PyEval_BuiltinsFromGlobals` with `_PyDict_LoadBuiltinsFromGlobals`, which returns a new reference instead of a borrowed reference. Internally, the new function uses per-thread reference counting when possible to avoid contention on the refcount fields on the builtins module.
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 05ae6a6 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
This is the final PR in the series to address the reference count contention with nested functions. After this PR, the "nested function" microbenchmark scales well in 3.14. |
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.
LGTM
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.
LGTM
PyObject * | ||
_PyDict_LoadBuiltinsFromGlobals(PyObject *globals) | ||
{ | ||
if (!PyDict_Check(globals)) { |
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.
maybe just add assertion as it is internal only API
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.
Some of the callers can pass in a non-dict "globals". IIRC, test_eval_code_ex.py
tests for this case and expects a SystemError
.
…GH-125847) This replaces `_PyEval_BuiltinsFromGlobals` with `_PyDict_LoadBuiltinsFromGlobals`, which returns a new reference instead of a borrowed reference. Internally, the new function uses per-thread reference counting when possible to avoid contention on the refcount fields on the builtins module.
This replaces
_PyEval_BuiltinsFromGlobals
with_PyDict_LoadBuiltinsFromGlobals
, which returns a new reference instead of a borrowed reference. Internally, the new function uses per-thread reference counting when possible to avoid contention on the refcount fields on the builtins module.