SubmarinerApp / Submariner

A Subsonic client for macOS
https://submarinerapp.com
BSD 3-Clause "New" or "Revised" License
140 stars 4 forks source link

Further reduce CPU usage when refreshing UI #171

Closed skyline75489 closed 1 year ago

skyline75489 commented 1 year ago
skyline75489 commented 1 year ago

I was also trying to handle the state when the application is completely hidden (covered by other application). This causes the application to become "background" in Instrument:

截屏2023-10-16 08 48 36

But I failed to find a way to do so. Any idea?

NattyNarwhal commented 1 year ago

I was also trying to handle the state when the application is completely hidden (covered by other application).

Technically if the window is still open but obscured, it can still be rendered because vibrancy material in a window in front of it, or being pulled in exposé. Maybe occlusionState (which has a notification) can help?

skyline75489 commented 1 year ago

Oh yeah, exposé. That's a feature that I haven't been used for quite some time. Maybe we can at lease reduce the refresh rate to 1sec when the window is not visible based on occlusionState. Even without handling occlusionState, the CPU usage is now at ~2% when the window is minimized with this PR. This is about the right amount of CPU usage I'd expect from a music app.

NattyNarwhal commented 1 year ago

Regarding occlusionState with some quick tests:

Overall, it looks like a better option that handles almost all window-not-visible states.

skyline75489 commented 1 year ago

Seems that occlusionState is way better than Miniaturization. I'll find some time to update this PR later 🥂

skyline75489 commented 1 year ago

You OK with other changes in this PR? Let me know if I'm doing something weird. I haven't really been an expert regarding macOS. I had my time developing on iOS several years ago.

NattyNarwhal commented 1 year ago

I left a comment regarding the change to clearPlaybackProgress; the miniaturization one we just addressed.

skyline75489 commented 1 year ago

Could it be that you didn't submit the review? I didn't see any comment. I sometimes also forget the submission :)

NattyNarwhal commented 1 year ago

FWIW, retested:

  • Switching workspaces definitely makes the window be not visible in occlusionState. Switching window via the dock or Cmd+Tab will make it be not visible, but using exposé or selecting another to switch doesn't seem to trigger that occlusion event.

This doesn't seem to be accurate after I checked again; occlusion behaves normally if completely obscured.

NattyNarwhal commented 1 year ago

I think this looks good to me.