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/WVQNATE7KYU5G64BQB5VEWALPYVS3QPV/ 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-counting-for-some-objects -- Jonathan
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@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/RYMLY4IVTCTIXZRXQAVLBKO4ZQAEH3WG/ Code of Conduct: http://python.org/psf/codeofconduct/