3 ms·
> This is lightweight, by way of comparison: until quite recently, Python's header tax was 308 bytes Really? I thought that PyObject_HEAD only contains two mac
by nwellnhof 2y ago
> This is lightweight, by way of comparison: until quite recently, Python's header tax was 308 bytes
Really? I thought that PyObject_HEAD only contains two machine words.
- masklinn 2y agoYou are correct, but PyObject_HEAD is not the full header for the average object. - the base requirement is a class pointer and a refcount, that's PyObject_HEAD (and PyObject) - then unless you have disabled this at compilation time, they have two pointers for the cycle-breaking part of the GC - a dict pointer (or as many instance value pointers as there are object members when using slots) - and a weakrefs pointer (except for slotted classes, unless you added it back) That is however only 6 words (48 bytes), or 4 (32) for slotted classes with no members or weakrefs. I believe the header is larger when running without GIL on 3.13 because PyObject has 2 more words (a local refcount, a gc bitset, and a mutex packed in a word with some padding, and a tid pointer). Still nowhere near 308 though, I've no idea where they got that. Maybe whoever wrote that article included the instance dict in their calculations? That would add 200~300 bytes. Or maybe they got mixed up between bits and bytes, calculated 308 bits somehow then wrote that up as bytes.
- deleted 2y ago[deleted]