mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-118527: Intern code consts in free-threaded build (#118667)
We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
This commit is contained in:
parent
8d8275b0cf
commit
723d4d2fe8
14 changed files with 375 additions and 18 deletions
|
|
@ -1985,6 +1985,17 @@ set_immortalize_deferred(PyObject *self, PyObject *value)
|
|||
#endif
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
get_immortalize_deferred(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
#ifdef Py_GIL_DISABLED
|
||||
PyInterpreterState *interp = PyInterpreterState_Get();
|
||||
return PyBool_FromLong(interp->gc.immortalize.enable_on_thread_created);
|
||||
#else
|
||||
Py_RETURN_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
has_inline_values(PyObject *self, PyObject *obj)
|
||||
{
|
||||
|
|
@ -2081,6 +2092,7 @@ static PyMethodDef module_functions[] = {
|
|||
{"py_thread_id", get_py_thread_id, METH_NOARGS},
|
||||
#endif
|
||||
{"set_immortalize_deferred", set_immortalize_deferred, METH_VARARGS},
|
||||
{"get_immortalize_deferred", get_immortalize_deferred, METH_NOARGS},
|
||||
#ifdef _Py_TIER2
|
||||
{"uop_symbols_test", _Py_uop_symbols_test, METH_NOARGS},
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue