question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issue

See original GitHub issue

I made a simple test where I draw multiple identical vertical lines from bottom to top in cycle. I found out that each new line renders much slower than previous one. Is it a bug or did I do something wrong?

def c(coord):
  if isinstance(coord, (np.ndarray, list)) and len(coord) == 3:
    return np.asarray(coord, dtype=np.float32) / 135
  else:
    return coord / 1.35

import numpy as np
from datetime import datetime

class mainScene(Scene):
  CONFIG = {
      "camera_config": {"background_color": '#ffffff'},
  }
  def construct(self):
    for j in np.arange(-958.5, 960, 2):
      start = datetime.now()
      for _ in np.arange(-540, 540, 2):
        line = Line(c([j, _, 0]), c([j, _+1, 0]), stroke_width=c(1), stroke_color='#000000')
        self.add(line)
        if _ == 538: print(int(j + 959.5), datetime.now() - start)
    
    self.wait(.1)

1 0:00:00.389817
3 0:00:00.927884
5 0:00:01.458466
7 0:00:01.970841
9 0:00:02.500315
11 0:00:03.015520
13 0:00:03.712525
15 0:00:04.210232
17 0:00:04.822479
19 0:00:05.358658
21 0:00:06.160043

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
zavdencommented, Feb 28, 2020

self.remove(mob1,mob2,...)

1reaction
zavdencommented, Feb 27, 2020

That is quite obvious if you think about how Manim should be working internally. Manim draws each object in each frame according to the preset order in the variable self.mobjects, as you already know self.add (mob) adds mob to self.mobjects. That means that the more mobjects added to the animation, more mobjects each frame will have to draw, for memory consumption. If you add 1000 mobjects with self.add then in each frame the 1000 mobjects will have to be added according to the order of self.mobjects. There is no way around this because Manim was designed this way.

This behavior is not similar to self.play, because the animated object is not successively added to memory. For example:

self.add(circle)
self.play(circle.shift,LEFT)

In this animation there is only one circle object, and in the course of the animation no other mobject is added or removed, all objects in self.mobjects remain intact, self.mobjects is the same before and after the animation. There are some animations that can delete (FadeOut, etc.) or add (FadeIn, Write, GrowFromCenter, etc.) an object at the end, but they do not do it in large quantities as you intend to do so.

Manim was not designed for such complex animations, Grant himself on his official website has said this, if Manim is not trained to do this I recommend using some other animation tool, such as Blender (in which you can also use Python 3).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing with Performance Problems
Types of Performance Problems ; Quantity of work (untimely completion, limited production). Poor prioritizing, timing, scheduling; Lost time ; Quality of work ( ......
Read more >
9 Examples of a Performance Issue - Simplicable Guide
A performance issue is a failure to meet the basic requirements of a job. They are based on reasonable expectations of behavior and...
Read more >
Handling Performance Issues With Grace | Monster.com
Low Productivity or Late Completion – Make sure you've been clear about the requirements and expectations of the job. · Poor Quality of...
Read more >
Top 5 Common Performance Problems - HRCI
Top 5 Common Performance Problems · Shallow Work · Inability to Prioritize · False Sense of Urgency · Productive Procrastination · Low-Quality Output....
Read more >
5 Common Reasons for Performance Issues (Plus 3 Tips to ...
Most Common Causes of Performance Issues · 1. They lack knowledge or skill. · 2. They have unclear or unrealistic expectations. · 3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found