-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hidden classes #6
Comments
Using |
My biggest reservation about this is the complexity of handling dictionaries that are explicitly accessed and modified. |
Another option to consider, is to lay out the dictionary's values directly after the object header and add a flag to the dictionary to indicate that layout was used. |
That's very clever. I suppose when the dict gets extended beyond the original set of keys the values get copied to a new array, and the original object just has a bunch of dead space. That seems reasonable. But we'd need a flag in the object (not its type) indicating that this arrangement is valid, if we wanted something like a LOAD_ATTR_SLOT specialized opcode (or special handling for slots in the LOAD_ATTR inline cache, as in current master). That flag would probably end up costing 8 bytes, but without that flag we'd always have to go through the dict object header (which might be fine). |
Typically the workaround for that is to not use hidden classes for those classes and instead fallback on dictionaries. |
See also #72. |
This is now obsolete. |
See my hick branch
My idea:
__dict__
after__init__
returns.ht_cached_keys
.)__slots__
machinery: for each attribute there's a reserved slot in the instance.C
, the hidden classC_
inherits directly fromC
.C
pointing toC_
.LOAD_ATTR
.LOAD_ATTR_SLOT
andSTORE_ATTR_SLOT
.Stuff to do:
C
andC_
D
ofC
, which gets its own hidden classD_
. (Need to ensure slots line up.)self.__class__
should point toC
, notC_
__dict__
should somehow deoptimize the object (but not the class)C_
be allowed to appear inC.__subclasses__()
?Critique:
LOAD_ATTR
inline cache (which caches the index in the array of values) there is a fair amount of pointer chasing needed to get to the value.__slots__
compared to the same class without__slots__
to assess whether to pursue this further.The text was updated successfully, but these errors were encountered: