-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-134761: Use deferred reference counting for threading
concurrency primitives
#134762
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
e02137e
6093acb
478d482
f0fc73c
d407ad9
c750d92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Improve performance when using :mod:`threading` primitives across multiple | ||
threads. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Data members: | |
*/ | ||
|
||
#include "Python.h" | ||
#include "object.h" | ||
#include "pycore_audit.h" // _Py_AuditHookEntry | ||
#include "pycore_call.h" // _PyObject_CallNoArgs() | ||
#include "pycore_ceval.h" // _PyEval_SetAsyncGenFinalizer() | ||
|
@@ -2653,6 +2654,23 @@ sys__is_gil_enabled_impl(PyObject *module) | |
#endif | ||
} | ||
|
||
/*[clinic input] | ||
sys._defer_refcount -> bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please document it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See Ken and Donghee's comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I disageee with them. IMO we should document sys functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would only be supportive of documenting this if we were allowed to change it in a minor version with no deprecation period. My understanding is that One way to "bypass" this is make the function a no-op in future versions of Python once we solve this issue altogether. But I don't know what users will rely on by then so I'm a bit worried. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I thought we were allowed to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're getting a bit hung up on this point. We can add or remove the documentation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I am preparing a better proposal for this approach. Give me hours. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, cool. Feel free to cc me on it. Something we also need to consider is whether we want to address this for 3.14. Should this general idea be considered a bugfix or a feature? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See: #134819 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this is improvement rather than bug fix. |
||
|
||
op: object | ||
/ | ||
|
||
Defer reference counting for the object, allowing for better scaling across multiple threads. | ||
|
||
This function should be used for specialized purposes only. | ||
[clinic start generated code]*/ | ||
|
||
static int | ||
sys__defer_refcount_impl(PyObject *module, PyObject *op) | ||
/*[clinic end generated code: output=3b965122056085f5 input=a081971a76c49e64]*/ | ||
{ | ||
return PyUnstable_Object_EnableDeferredRefcount(op); | ||
} | ||
|
||
#ifndef MS_WINDOWS | ||
static PerfMapState perf_map_state; | ||
|
@@ -2834,6 +2852,7 @@ static PyMethodDef sys_methods[] = { | |
SYS__GET_CPU_COUNT_CONFIG_METHODDEF | ||
SYS__IS_GIL_ENABLED_METHODDEF | ||
SYS__DUMP_TRACELETS_METHODDEF | ||
SYS__DEFER_REFCOUNT_METHODDEF | ||
{NULL, NULL} // sentinel | ||
}; | ||
|
||
|
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.
Can you move the call after initializing
self->lock
? Same remark forrlock_new_impl()
below.