On Wed, Dec 15, 2021 at 6:21 PM Guido van Rossum <guido@python.org> wrote:
On Wed, Dec 15, 2021 at 2:57 PM Guido van Rossum <guido@python.org> wrote:

I don't know how long that would take, but I suspect that a program that just increments the refcount relentlessly would have to run for hours before hitting this range. On a 64-bit machine the same approach would require years to run before a refcount would exceed the maximum allowable imbalance. (These estimates are from Mark Shannon.)

Hm, not quite. I modified a fast builtin to incref its argument, and then I called it in a `while True` loop, interrupted, and timed it. This did ~24,000,000 INCREFs/second. This would hit 0x_2000_0000 in about 9 minutes. And I wasn't even trying that hard -- I could have written the loop in C. (I did comment out an audit call though. :-) The same loop on 64-bit would take 1700 years to reach the limit, so we're safe there.

Similar 32-bit vs 64-bit overflow estimates were made by Victor Stinner in the dict version tag PEP 509
https://www.python.org/dev/peps/pep-0509/#integer-overflow

tldr 4sec on 32-bit and 584 years on 64-bit
Granted, the risk there is only for *exactly* `2 ** (Nbits)` increments.
 

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@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/2PQVABDBGJEKRBGVLOQEFY72KZO66W3J/
Code of Conduct: http://python.org/psf/codeofconduct/