Currently when the __dict__ attribute of an object is accessed we transfer ownership of the values array from the object to the dict.
Accessing the __dict__ of an object is fairly uncommon, but not that uncommon, but it is highly disruptive to optimizations.
We currently attempt to mitigate this by dematerializing the __dict__, but that has a few failings:
- It bulks out a common and performance critical uop,
_CHECK_MANAGED_OBJECT_HAS_VALUES
- It isn't that effective
- It is not thread safe
Rather than attempting to get rid of the dictionary, lets change the object and values so that the presence of a __dict__ doesn't impact the fast path.
What that means is that an object would still retain a pointer to the values, even if the dict were present.
Inlining the values would help here. Otherwise we need an extra pointer, bulking out the pre-header even more.
Memory management becomes a little more complex, as we need to make sure that we don't free the values when there is a still a reference to it. We can use reference counting, but we will only need a single bit as the values can only be referred to by the object and/or the dict.
@brandtbucher thoughts?
Currently when the
__dict__attribute of an object is accessed we transfer ownership of the values array from the object to the dict.Accessing the
__dict__of an object is fairly uncommon, but not that uncommon, but it is highly disruptive to optimizations.We currently attempt to mitigate this by dematerializing the
__dict__, but that has a few failings:_CHECK_MANAGED_OBJECT_HAS_VALUESRather than attempting to get rid of the dictionary, lets change the object and values so that the presence of a
__dict__doesn't impact the fast path.What that means is that an object would still retain a pointer to the values, even if the dict were present.
Inlining the values would help here. Otherwise we need an extra pointer, bulking out the pre-header even more.
Memory management becomes a little more complex, as we need to make sure that we don't free the values when there is a still a reference to it. We can use reference counting, but we will only need a single bit as the values can only be referred to by the object and/or the dict.
@brandtbucher thoughts?