"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.)