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`
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:
--
Jonathan