> On 28 Apr 2020, at 20:38, Jim J. Jewett <jimjjew...@gmail.com> wrote: > > Why do sub-interpreters require (separate and) heap-allocated types? > > It seems types that are statically allocated are a pretty good use for > immortal objects, where you never change the refcount ... and then I don't > see why you need more than one copy.
I guess it depends… One reason is type.__subclasses__(), that returns a list of all subclasses and when a type is shared between sub-interpreters the return value might refer to objects in another interpreter. That could be fixed by another level of indirection I guess. But extension types could contain other references to Python objects, and it is a lot easier to keep track of which subinterpreter those belong to when every subinterpreter has its own copy of the type. If subinterpreters get their own GIL maintaining the refcount is another reason for not sharing types between subinterpreters. “Never changing the refcount” could be expensive in its own right, that adds a branch to every invocation of Py_INCREF and Py_DECREF. See also the benchmark data in <https://bugs.python.org/issue40255 <https://bugs.python.org/issue40255>> (which contains a patch that disables refcount updates for arbitrary objects). Ronald — Twitter / micro.blog: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/DAKZI7352EWIMJ7Y2YLHPCHJST7DIZWB/ Code of Conduct: http://python.org/psf/codeofconduct/