Multithreaded Rendering? #3897
Replies: 1 comment 8 replies
-
I think the developers have had lots of conversations about this - if you have any questions, feel free to ping us on discord :) The problem is really in two parts - the current architecture of Manim is insufficient to handle multithreading correctly, and the user has an incredible amount of "power" in what they can do. I'll tackle the second point first, because it's easier to describe. Take this code for example: sq = Square()
self.add(sq)
self.play(sq.animate.shift(RIGHT))
self.play(FadeOut(sq)) It's pretty obvious that the way the second animation ( Now, the next thought is to make the user explicitly opt-in to threading their code (maybe checking if updaters exist, or forcing users to mark updaters with an attribute if they are "pure"). Trying to handle this with our current architecture (relevant docs) is an absolute nightmare, and is bound to cause bugs. In order to do this in the least hacky way possible, we would have to rewrite the But now! All hope is not lost! Unlike what it may seem like, the devs are still making huge leaps towards improving Manim. We have a refactor branch where we've rewritten the renderer and |
Beta Was this translation helpful? Give feedback.
-
I'm not too familiar with the internals of Manim or how python does threading, or even python if I'm being honest (I'm really only learning python in order to use Manim), so there might be something preventing this from being viable that I cannot see... but it seems to me that there's a big missed opportunity in not threading the rendering process.
I'm making video's that have hundreds of animations in a 10-minute run-time and it takes upwards of 30 minutes to even re-render (with 90% of clips only being hashed) after a small edit.
My thought is this: wouldn't the hashing/clip-re-use process provide an ideal junction point for threading the process? everything required to uniquely specify an animation is gathered together for the process of hashing it. If all of that gets packaged up and handed to a worker thread as its task (deep object copy?) - to hash and then render if required - then all that is required is to simulate the results of the animation, which i presume is done anyway if the hash finds the render unnecessary, and continue with running the user code in the main thread.
Wait for all the render threads to return the files they've identified/rendered, smoosh them together as usual, done.
It's probably sensible to limit the number of concurrent threads to the N of CPU threads by blocking the main thread waiting on any worker thread return when starting the Nth thread.
The progress reporting might have to be re-written for handling multiple simultaneous renders, but that's not a big issue.
Beta Was this translation helpful? Give feedback.
All reactions