You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At each removed mobject, the code mobject in self.submobjects is executed and performs linear search over a list, which is far from optimal if self.submobjects is large (even if mobjects is small). It would be more efficient to use an object that allows for O(1) membership checks, like a dict or a set (or an OrderedDict).
The text was updated successfully, but these errors were encountered:
On the one hand, there are no repeated Mobjects in a scene, Scene.mobjects could be a set, not a lost. On the other hand, the code originally used the position of each Mobject in that list to determine the drawing order. But now that is done via Mobject.z_index.
So, in principle, I think we could change Scene.mobjects to be a set, and delete a while bunch of legacy code. Can anyone think of objections?
We are thinking of not using z_index anymore, so my last comment doesn't work anymore.
On the topic of this issue: I think there are deeper refactorings to be done with submobjects (#358), so whatever is done to fix the present issues would be temporary at best. Closing for now.
This is a fairly edge-case optimization, so please feel free to close this if it's deemed to niche.
Currently, the definition of
Mobject.remove
does this:At each removed mobject, the code
mobject in self.submobjects
is executed and performs linear search over a list, which is far from optimal ifself.submobjects
is large (even ifmobjects
is small). It would be more efficient to use an object that allows forO(1)
membership checks, like a dict or a set (or an OrderedDict).The text was updated successfully, but these errors were encountered: