Only redraw when something has changed / High CPU usage

Issue #43 new
Matthias Schoettle created an issue

TouchRAM has a high CPU usage even if nothing is done, i.e., even if it runs in the background. On a recent rMBP it has a constant CPU usage of 40-45%!

When profiling the CPU with JProfiler it shows that drawing is something that takes a lot. Therefore, it could mean that MT4j constantly redraws everything on the screen, even if that is not necessary, because nothing has changed.

Comments (7)

  1. Matthias Schoettle reporter

    AbstractMTApplication.draw() (line 271) gets called constantly (i.e., every loop), which invokes the private method runApplication. From there, the drawAndUpdate method of the current scene is called, which leads to the scene being cleared and redrawn. Eventually this will lead to every child of the scenes canvas being redrawn.

  2. Matthias Schoettle reporter

    Processing contains support for redrawing. I am surprised MT4j doesn't use this.

    That means, draw() gets executed in a loop, but can be stopped with noLoop(). redraw() allows to draw once or loop() to continue looping again. It seems that has to be implemented manually.

  3. Matthias Schoettle reporter

    I tried to stop the loop using noLoop(). However, in the loop, runApplication of AbstractMTApplication is called. In that method, the first task is to process incoming events. This means that, stopping the loop stops processing of events. For some reason, drawing and event processing are intertwined in MT4j.

  4. Log in to comment