[issue39511] [subinterpreters] Per-interpreter singletons (None, True, False, etc.)

STINNER Victor report at bugs.python.org
Tue Mar 17 12:54:19 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

Mark:
> The problem with having a single immortal `None`, is that it will cause data cache thrashing as two different CPUs modify the refcount on the shared `None` object.

Yeah, I concur with Mark: having one singleton per interpreter should provide better usage of the CPU caches, especially CPU data cache level 1.


Mark:
> Consider the case where a thread that doesn't hold the GIL attempts to get a reference on `None`.

The main drawback of PR 18301 is that accessing "Py_None" means accessing tstate->interp->none. Except that the commonly used _PyThreadState_GET() returns NULL if the thread doesn't hold the GIL.

One alternative would be to use PyGILState_GetThisThreadState() but this API doesn't support subinterpreters.

Maybe we are moving towards a major backward incompatible changes required to make the subinterpreters implementation more efficient.

Maybe CPython should have a backward compatible behavior by default (Py_None can be read without holding the GIL), but running subinterpreters in parallel would change Py_None behavior (cannot be read without holding the GIL).

I don't know.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39511>
_______________________________________


More information about the Python-bugs-list mailing list