What's the public API alternative to _PyObject_GC_IS_TRACKED()?

Dieter Maurer dieter at handshake.de
Wed Dec 29 04:06:23 EST 2021


Marco Sulla wrote at 2021-12-29 09:29 +0100:
>On second thought, I think I'll do this for the pure py version. But I
>will definitely not do this for the C extension

Are you sure you need to implement your type in C at all?

I made a small `timeit` test:
```
>>> class cd(dict): pass
...
>>> timeit("d[1]", "d={1:1}", globals=globals())
0.02474160000019765
>>> timeit("d[1]", "d=cd({1:1})", globals=globals())
0.08281239100051607
```
This means that for the above trivial case, access is 3.5 times slower
(the difference is smaller for more complex cases when hashing
becomes more expensive) but it is still only 83 ns per access.
Thus, if your application is not highly dominated by dict accesses,
the overall difference will not be large.


More information about the Python-list mailing list