maplibre-rs icon indicating copy to clipboard operation
maplibre-rs copied to clipboard

maplibre-demo: High CPU and GPU usage on macOS while idle

Open vollkorntomate opened this issue 2 years ago • 10 comments

The maplibre-demo binary has a quite high CPU and GPU usage when doing nothing. Activity monitor shows around 40% CPU usage and between 25-35% GPU usage while the app is in the foreground (and has focus) and no layers are being visibly rendered and the map is not interacted with. Roughly the same usage is reported while the app is in the background (window has no focus)

🤔 Expected Behavior

The CPU and GPU usage should be at a minimum, near 0%.

😯 Current Behavior

See above.

The latest commits (from Oct 23 and 24) seem to have improved the issue. Earlier, GPU usage was near 100% while in background. However, this improvement might also be due to the macOS Ventura update.

💁 Possible Solution

I was able to narrow down the source of the problem to apparently be inside maplibre-winit/src/winit/mod.rs:170 and the call to map_schedule::InteractiveMapSchedule::update_and_redraw(), since the RedrawRequested event fires multiple times per second and thus the map re-renders all the time, costing CPU and GPU resources.

A possible solution might be to only redraw the map if

  1. it has been moved or zoomed since the last redraw or
  2. loading the map hasn't finished and thus new objects need to be rendered

🌍 Your Environment

  • Desktop
    • macOS 13.0 (Ventura)
    • M1 Max, 24 GPU Cores
  • commit ec1ad07
  • built with cargo build -p maplibre-demo
  • run with ./target/debug/maplibre-demo headed

vollkorntomate avatar Oct 25 '22 16:10 vollkorntomate