On 2019-03-03, Nick Coghlan wrote:
Note that moving reference counts to a separate table is something we've previously discussed doing for CPython itself
I suspect as long as we are using reference counting GC for CPython (which is realistically probably forever), the sensible choice will be to have the counts located with the object. However, IMHO, the extension API should not force the VM into that design.
The complete unknown from a performance persecptive is the potential CPU cache management impact of switching from scattered writes to a lot of different memory blocks to frequent writes to a particularly hot memory page (although we know up front that the centralised table will be far more copy-on-write friendly without any need for gc.freeze() shenanigans).
I was watching an interesting video today talking about the cost of scattered memory access on modern hardware:
The benchmarks on the Samsung tablet are interesting. CPython is very sparse (like Java/C# in the presentation, but worse yet). If you want to look at the refcnt for many objects (e.g. during cyclic GC pass), it would help to put them in a contiguous array. However, in normal execution, you are already going to have to object data in cache and so it makes sense to have the refcnt there too.