On 2021-12-15 2:57 p.m., Guido van Rossum wrote:
But as long as the imbalance is less than 0x_2000_0000, the refcount
will remain in the inclusive range [ 0x_4000_0000 , 0x_7FFF_FFFF ] and
we can test for immortality by testing a single bit:
if (o->ob_refcnt & 0x_4000_0000)
Could we have a full GC pass reset those counts to make it even more
unlikely to get out of bounds?
Allocating immortal objects from a specific memory region seems like
another idea worth pursuing. It seems mimalloc has the ability to
allocate pools aligned to certain large boundaries. That takes some
platform specific magic. If we can do that, the test for immortality
is pretty cheap. However, if you can't allocate them at a fixed region
determined at compile time, I don't think you can match the performance
of the code above. Maybe it helps that you could determine immortality
by looking at the PyObject pointer and without loading the ob_refcnt
value from memory? You would do something like:
if (((uintptr_t)o) & _Py_immortal_mask)
The _Py_immortal_mask value would not be known at compile time but would
be a global constant. So, it would be cached by the CPU.
_______________________________________________
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/BESETUOZGP6NZ37F32DUBEYZ4BUK2UWD/
Code of Conduct: http://python.org/psf/codeofconduct/