On 10. 03. 22 3:35, Jim J. Jewett wrote:
"periodically reset the refcount for immortal objects (only enable this
if a stable ABI extension is imported?)" -- that sounds quite expensive,
both at runtime and maintenance-wise.
As I understand it, the plan is to represent an immortal object by setting two
high-order bits to 1. The higher bit is the actual test, and the one
representing half of that is a safety margin.
When reducing the reference count, CPython already checks whether the refcount's
new value is 0. It could instead check whether refcount & (not !immortal_bit)
is 0, which would detect when the safety margin has been reduced to 0 -- and could
then add it back in. Since the bit manipulation is not conditional, the only extra
branch will occur when an object is about to be de-allocated, and that might be
rare enough to be an acceptable cost. (It still doesn't prevent rollover from too
many increfs, but ... that should indeed be rare in the wild.)
The problem is that Py_DECREF is a macro, and its old behavior is
compiled into some extensions. We can't change this without breaking the
stable ABI.
_______________________________________________
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/FPKK46N4RBAEJUU5PCQZ3SIZ7GREETTH/
Code of Conduct: http://python.org/psf/codeofconduct/