mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-84436: Implement Immortal Objects (gh-19474)
This is the implementation of PEP683 Motivation: The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime. Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
This commit is contained in:
parent
916de04fd1
commit
ea2c001650
35 changed files with 483 additions and 171 deletions
|
@ -318,27 +318,11 @@ _PyType_InitCache(PyInterpreterState *interp)
|
|||
entry->version = 0;
|
||||
// Set to None so _PyType_Lookup() can use Py_SETREF(),
|
||||
// rather than using slower Py_XSETREF().
|
||||
// (See _PyType_FixCacheRefcounts() about the refcount.)
|
||||
entry->name = Py_None;
|
||||
entry->value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// This is the temporary fix used by pycore_create_interpreter(),
|
||||
// in pylifecycle.c. _PyType_InitCache() is called before the GIL
|
||||
// has been created (for the main interpreter) and without the
|
||||
// "current" thread state set. This causes crashes when the
|
||||
// reftotal is updated, so we don't modify the refcount in
|
||||
// _PyType_InitCache(), and instead do it later by calling
|
||||
// _PyType_FixCacheRefcounts().
|
||||
// XXX This workaround should be removed once we have immortal
|
||||
// objects (PEP 683).
|
||||
void
|
||||
_PyType_FixCacheRefcounts(void)
|
||||
{
|
||||
_Py_RefcntAdd(Py_None, (1 << MCACHE_SIZE_EXP));
|
||||
}
|
||||
|
||||
|
||||
static unsigned int
|
||||
_PyType_ClearCache(PyInterpreterState *interp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue