well, the problem is that the code calling the refcount doen'st know those
objects are "special", and thus need to call  Py_INCREF and Py_DECREF
anyway.

So are you suggesting that Py_INCREF and Py_DECREF do a check to see if the
objects is "special" in this way, and not actually change the refcount?
Would that really help performance at all?

BTW, you could probably check this with little understanding of cPython
internals by simply hacking those two functions (macros?) to be no-ops, and
and see how it affects performance.

-CHB


On Sat, Jun 13, 2020 at 3:49 AM Jonathan Fine <jfine2...@gmail.com> wrote:

> 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/
>


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
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/DO7NA4TT2HQYUUZKO7V5RP7EZFIIELQY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to