Replies: 6 comments 8 replies
-
do you mean this? otherwise static inline void _Py_DECREF(PyObject *op)
{
if (op->ob_refcnt > 1) {
op->ob_refcnt--;
}
else {
// No decrement needed.
// Try not to write to the soon-to-be-freed memory.
Py_TYPE(op)->tp_dealloc(op);
}
} |
Beta Was this translation helpful? Give feedback.
-
This is worth an experiment to see if it makes a difference, but I worry that it will break the stable ABI, and also that there are many additional APIs around refcounting that will have to be adjusted before it passes all the tests. |
Beta Was this translation helpful? Give feedback.
-
I would recommend changing the name of |
Beta Was this translation helpful? Give feedback.
-
There are two parts to this change:
Change 1 is less likely to break anything. |
Beta Was this translation helpful? Give feedback.
-
I don't think I have the bandwidth for this at the moment, so if anyone wants to try this out, feel free. |
Beta Was this translation helpful? Give feedback.
-
Change 1 by itself sounds like a nightmare for finalizers, weakrefs, GC, etc. There would now be two very different meanings of
I don't see much value in testing change 2 without change 1, and I don't really see how we can test only change 1 without giving ourselves lots of headaches and extra work.
Edit: Ah, I think I misunderstood the original proposal. Biasing doesn't change the fact that we can't tell living and dying objects apart. |
Beta Was this translation helpful? Give feedback.
-
In this interesting 2014 C++ talk by Andrei Alexandrescu (slides), the speaker mentions that ref-counting performance of a shared pointer can improve by biasing all refcounts by -1. That way, we could change:
to
Since reference counts are typically small, the percentage of memory writes saved could be significant.
For compatibility, we could even define
Beta Was this translation helpful? Give feedback.
All reactions