There's a PR for this: "Immortal instances", by Eddie Elizondo (Facebook).
Github PR: https://github.com/python/cpython/pull/19474
Bug Report: https://bugs.python.org/issue40255
On Sat, Jun 13, 2020 at 3:48 AM Jonathan Fine
Hi
Here's something that might make code run quicker. The basic idea is to not refcount some objects that are sure never to be deleted. On a multicore machine, this might significantly reduce the number of cache invalidations (and perhaps misses). I lack many of the skills needed to investigate this further.
Aside: This idea prompted by: Make `del x` an expression evaluating to `x`
https://mail.python.org/archives/list/python-ideas@python.org/message/WVQNAT...
Consider
tuple(id(n) - id(0) for n in range(10)) (0, 32, 64, 96, 128, 160, 192, 224, 256, 288)
Why? Small integers are stored at fixed locations, hence the arithmetic progression. Let's look at refcounts.
import sys tuple(sys.getrefcount(n) for n in range(10)) (511, 837, 113, 54, 63, 35, 30, 20, 65, 17)
These refcounts are variable numbers. They can be changed (within limits).
x = [0] * 100000 tuple(sys.getrefcount(n) for n in range(10)) (100510, 837, 113, 54, 63, 35, 30, 20, 65, 17)
The same happens with None.
sys.getrefcount(None) 8475 x = [None] * 100000 sys.getrefcount(None) 108475
For me the basic idea of the implementation would be to not refcount those objects, whose id lies in a certain range. As stated earlier, I suspect the main benefit will be on multicore machines being able to make better use of per-core caches.
If anyone is interested, I suggest starting with None, to get a rough estimate of the possible benefits (and cost of implementation).
As well as the python-ideas thread mentioned above, related to this is:
https://stackoverflow.com/questions/14139111/python-disable-reference-counti...
-- Jonathan _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RYMLY4... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...