On 22/09/20 10:06 pm, Victor Stinner wrote:
I wrote a simple implementation which leaves the code as it is, but "unbox" tagged pointers when a function access directly object members. Example in listobject.c:
vl = (PyLongObject*)_Py_TAGPTR_UNBOX(v); wl = (PyLongObject*)_Py_TAGPTR_UNBOX(w); v0 = Py_SIZE(vl) == 0 ? 0 : (sdigit)vl->ob_digit[0]; w0 = Py_SIZE(wl) == 0 ? 0 : (sdigit)wl->ob_digit[0];
I think you're using the terms "box" and "unbox" the opposite way from most people. Usually a "boxed" type is one that lives on the heap, and an "unboxed" one doesn't.
My first goal was to write a *correct* (working) implementation, not really an optimized implementation.
That's why I'm calling for help to attempt to optimize it ;-)
What are you trying to achieve by using tagged pointers? It seems to me that in a dynamic environment like Python, tagged pointer tricks are only ever going to reduce memory usage, not make anything faster, and in fact can only make things slower if applied everywhere. We already have ways of efficiently storing collections of ints and floats -- array.array, numpy, etc. -- and you only pay for the overhead of those if you need them. -- Greg