-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Description of bug / unexpected behavior
I am working on a project involving moderately large groups of mobjects (100s), which has actually never been a problem. But upgrading to 17.3 has made this process incredibly slow.
My code is a simple VGroup of VGroups. These inner VGroups are composed of a Rectangle and a Text object. That is ~100s of these VGroups which add up to double the quantity in total VMobjects.
In 0.17.2 this took absolutely no time, in 0.17.3 it takes tenths of seconds.
Setup
Inspecting a bit, turns out is about the multiple text objects. Let me provide some examples. All these are running in manim 0.17.3
Very slow
The following piece of code is a minimal working example of the setup I have. I actually have several classes and inheritance in my code, so this is what it'd look stripped down. We have a random 2D array and we iterate through it, creating a VGroup of a Square and some Text. Importantly, we are setting text properties such as the font attribute.
This piece of code takes a very long time to run. Unfortunately, I don't know how to measure manim run time. But hopefully the details help to those that can.
class Test(MovingCameraScene):
def construct(self):
big_kernel = np.random.randint(0, 255, (10, 10))
big_kernel_mob = (
VGroup(
*[
VGroup(
Square(),
Text(
f"{c}",
font="Arial",
weight=BOLD,
),
).arrange(ORIGIN)
for row in big_kernel
for c in row
]
)
.arrange_in_grid(rows=10, cols=10, buff=0)
.scale(0.3)
)
self.add(big_kernel_mob)
A bit faster
On the other hand, this very similar one runs normally fast. It's not immediate, but takes just under a second. The only difference is that the font is not being set, so it defaults to Times.
class Test(MovingCameraScene):
def construct(self):
big_kernel = np.random.randint(0, 255, (10, 10))
big_kernel_mob = (
VGroup(
*[
VGroup(
Square(),
Text(
f"{c}",
# font="Arial",
weight=BOLD,
),
).arrange(ORIGIN)
for row in big_kernel
for c in row
]
)
.arrange_in_grid(rows=10, cols=10, buff=0)
.scale(0.3)
)
self.add(big_kernel_mob)
The fastest
Even more so, if we ignore the matrix values and always use the same number, it runs even faster. One can assume that some text caching is going on with Pango, but I am not completely sure. Here, setting the font does not matter.
class Test(MovingCameraScene):
def construct(self):
big_kernel = np.random.randint(0, 255, (10, 10))
big_kernel_mob = (
VGroup(
*[
VGroup(
Square(),
Text(
f"{20}",
font="Arial",
weight=BOLD,
),
).arrange(ORIGIN)
for row in big_kernel
for c in row
]
)
.arrange_in_grid(rows=10, cols=10, buff=0)
.scale(0.3)
)
self.add(big_kernel_mob)
Changing to 0.17.2
However, if I reinstall manim at 17.2, the slowest piece of code now runs just as fast as usual. So, I guess some regression has happened in the new release.
System specifications
- OS: MacOS 13.2.1
- RAM: 16GB
Hopefully I didn't miss anything. Please let me know if any other details are needed! Thanks so much beforehand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status