The literature on reference counting for JVM and other GCs show that very few reference counts get to more than 7. This matches up with our stats that should the ratio of refcount ops to object allocations is about 6/7 to 1.
With that in mind, it would make sense to make the C ints used to represent refcounts smaller.
Instead of:
uint32_t ob_ref_local; // local reference count
Py_ssize_t ob_ref_shared; // shared (atomic) reference count
we can use:
uint8_t ob_ref_local; // local reference count
uint32_t ob_ref_shared; // shared (atomic) reference count
using 5 bytes instead of 12.
If ob_ref_local would overflow, we can atomically move some of that count into ob_ref_shared.
if (++op->ob_ref_local == 0) {
atomic_add(&op->ob_ref_shared, 128);
op->ob_ref_local = 128;
}
ob_ref_shared can use the same approach to saturation and immortality that the default build currently does.
The literature on reference counting for JVM and other GCs show that very few reference counts get to more than 7. This matches up with our stats that should the ratio of refcount ops to object allocations is about 6/7 to 1.
With that in mind, it would make sense to make the C ints used to represent refcounts smaller.
Instead of:
we can use:
using 5 bytes instead of 12.
If
ob_ref_localwould overflow, we can atomically move some of that count intoob_ref_shared.ob_ref_sharedcan use the same approach to saturation and immortality that the default build currently does.