OpenTimelineIO / raven

Raven - OpenTimelineIO Viewer Application
Apache License 2.0
74 stars 15 forks source link

Performance + power consumption issue #37

Open jminor opened 5 months ago

jminor commented 5 months ago

Raven naively uses Dear ImGui in a way that re-renders the window even when not needed. The application's performance & power consumption could be improved by fixing this oversight.

When I initially wrote Raven, this continuous rendering was problematic, and I attempted to use a branches of ImGui with support for ImGuiConfigFlags_EnablePowerSavingMode (see POWER_SAVING in the code). If I recall correctly Raven's WASM/Emscripten build suffered from this issue quite badly, and I was disappointed to see that the power saving mode didn't work in the browser environment due to specifics of how Emscripten works.

At the time, I set that aside for "later" figuring that Dear ImGui would improve and Raven's energy usage would improve by virtue of that change. As of this writing, that feature has not landed in ImGui.

Today (Feb 2024) I was curious to measure Raven's performance on macOS. A quick look at Raven in Activity Monitor shows that this is not a problem. The app consumes 0% CPU when it is not active, or when the user's cursor is not moving, and only about 10% when the user actively zooms/pans. I'm not entirely sure why or how that changed, so some investigation should be done. Also we should compare on other platforms (Windows, Linux) to see if those have also improved.

I also found that ocornut, Dear ImGui's author, has written this advice on the subject which looks pretty straight forward to implement, and which proposes a solution for the Emscripten scenario: https://github.com/ocornut/imgui/wiki/Implementing-Power-Save,-aka-Idling-outside-of-ImGui

So this issue is here to ask for help with the following:

jminor commented 5 months ago

Here's a simple CPU 0% measurement when idle on macOS (M1 MacBook Pro, running macOS 14.3):

Screenshot 2024-02-02 at 12 24 22 AM

and CPU 15% when active:

Screenshot 2024-02-02 at 12 25 04 AM
darbyjohnston commented 5 months ago

On Windows 10 compiled in "Release" mode with the AWS Picchu .otio file:

The numbers are from the Windows Task Manager.

For comparison the tlRender example applications (both GLFW and Qt based) have about the same performance when panning but go down to 0% when idle.

darbyjohnston commented 5 months ago

On Ubuntu 22.04 compiled in "Release" mode with the AWS Picchu .otio file:

The numbers are from the System Monitor.

That's strange, I wonder why there is such a large difference on Linux.

jminor commented 5 months ago

Thanks for testing this on the other platforms @darbyjohnston ! It looks like this is a bigger issue on Linux than the other platforms. I wonder if some operating systems throttle apps that aren't getting user input?

meshula commented 5 months ago

Perhaps on Mac/win the update is driven by the message pump, but on linux it's driven by a timer?

jminor commented 2 months ago

Interesting analysis of immediate mode UIs: https://www.forrestthewoods.com/blog/proving-immediate-mode-guis-are-performant/