Improve Updater signature checks for substantial speedups, add UpdaterWrappers and more Updater aliases#3807
Open
chopan050 wants to merge 13 commits intoManimCommunity:mainfrom
Open
Improve Updater signature checks for substantial speedups, add UpdaterWrappers and more Updater aliases#3807chopan050 wants to merge 13 commits intoManimCommunity:mainfrom
Updater signature checks for substantial speedups, add UpdaterWrappers and more Updater aliases#3807chopan050 wants to merge 13 commits intoManimCommunity:mainfrom
Conversation
JasonGrace2282
requested changes
Jun 17, 2024
Member
JasonGrace2282
left a comment
There was a problem hiding this comment.
Haven't looked through the whole thing, but just off a glance through, I left some comments
Hopefully, this makes the updater situation better in future versions of manim :)
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #321
General description
In the issue described, Leo mentions that calling
inspect.signature()every time we need to compute whether anUpdateris time-based or not, takes a considerable amount of time when there are a lot of updaters in a Scene.Leo proposed that every updater must always have two parameters and made a PR about it, but it was rejected.
Given an updater
func, my first attempt was accessingfunc.__code__.co_varnames(local variable names in the function code) and slice it from 0 tofunc.__code__.co_argcount(number of positional parameters) to get the names of positional parameters.However, as JasonGrace commented his concerns about more advanced use cases, I needed something more.
Therefore, in this PR I introduce a
MobjectUpdaterWrapper, which takes an updater function, saves it in its.updaterattribute, and usesinspect.signature()on it to calculate whether it's time-based or not. It stores the result in its.is_time_based, and this computation only happens once (when instantiatingMobjectUpdaterWrapper), rather than every time the updater is called, leading to a substantial speedup when updating Mobjects.In
MobjectUpdaterWrapperI also address the concerns raised by JasonGrace, Leo and myself:dtin the signature?dtvalue?self?selfanyways?which is why I decided to make a separate class in the first place: the logic which attempts to address all these concerns is very long and shouldn't bloat the
Mobject.add_updater()code. Plus, I wanted to replicate the same forOpenGLMobjectas well.Because I wanted to make the same changes in
OpenGLMobject, the best course of action was taking all this code into a different module, specificallymanim.utils.updaters.I also noticed that the relatively obscure classes
Object3Dand its subclassMeshalso have updaters which work in a very similar fashion, so I added theMeshUpdatertype alias and theMeshUpdaterWrapperclass as well.Finally,
Scenealso has updaters, but very different ones (they always accept adt: floatand returnNone), so I also added aSceneUpdatertype alias.Profiling
An example scene with many updaters:
Notice how the
inspect.signature()block completely disappears from theMobject.update()time:Links to added or changed documentation pages
https://manimce--3807.org.readthedocs.build/en/3807/reference/manim.utils.updaters.html
Further Information and Comments
Reviewer Checklist