Re:Why Python Is Slow: Looking Under the Hood
by dalke on Wednesday November 19, 2014 @05:45PM
(#8633186)
Those are excellent points. In the context of CPython, Guido van Rossum made the design decision to not use tagged objects, based on experience with ABC implementation, which did.
See https://mail.python.org/pipermail/python-dev/2004-July/04614... .
I just realized though that since the patch to support tagged integers is small, a closed system like the CCP Games distribution of Python, which has no extensions they don't control, might be able to use this idea.
> If small integers did not have a refcount then that extension would have to have special code, like "if object is not a small integer, then increment the reference count".
Easily implemented in one place in the "increment_refcount(obj)" inline function:
where "is_heap_pointer(obj)" is an inlined bitmask check like If TAG_PTR is zero bits, then a value which satisifes is_heap_pointer can be dereferenced straight.In a garbage collection implementation, you don't have refcounts, but the garbage collector's "mark object" function does the same check:
Another thing is that you provide an API to the extension writers, which abstracts the use of objects. For instance, you can give them a function that can be called like this: The first case might construct an unboxed value because the integer is small enough. But perhaps the second returns a bignum because INT_MAX requires 32 bits, wheres unboxed integers only go up to 30 bits.So in the first case you get an object with no refcount, whereas in the second you get an object with a refcount of 1. The extension code is written such that it doesn't care.