Stop rendering when the terminal has been minimized/control has been hidden #2791

Open
opened 2026-01-30 23:05:13 +00:00 by claunia · 5 comments
Owner

Originally created by @zadjii-msft on GitHub (Jul 16, 2019).

Ported from MSFT:21315817

We shouldn't render the XAML island when we're minimized.

I don't remember any more of the context on this one. It was assigned to @DHowett-MSFT, so he might remember.

Originally created by @zadjii-msft on GitHub (Jul 16, 2019). Ported from MSFT:21315817 We shouldn't render the XAML island when we're minimized. I don't remember any more of the context on this one. It _was_ assigned to @DHowett-MSFT, so he might remember.
claunia added the Help WantedIssue-TaskProduct-TerminalArea-UserInterface labels 2026-01-30 23:05:13 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 20, 2019):

Notes: when the terminal is minimized, we should just stop rendering. Right now, we don't do any detection that the app is not visible or that the tab the terminal is on has lost focus. We're probably spinning a lot of resources in the background to render invisible things.

@DHowett-MSFT commented on GitHub (Jul 20, 2019): Notes: when the terminal is minimized, we should just stop rendering. Right now, we don't do any detection that the app is not visible or that the tab the terminal is on has lost focus. We're probably spinning a lot of resources in the background to render invisible things.
Author
Owner

@AmineI commented on GitHub (Jun 16, 2020):

I'll add that heavy background gifs also continue using resources when the window is minimized. However a simple workaround is to switch to a tab with a static background before minimizing !

@AmineI commented on GitHub (Jun 16, 2020): I'll add that heavy background gifs also continue using resources when the window is minimized. However a simple workaround is to switch to a tab with a static background before minimizing !
Author
Owner

@mailinglists35 commented on GitHub (Feb 21, 2023):

When you work on fixing this, please also consider the case where the app is not minimized, but it has scrolling activity in inactive tabs.

Here's a quick reproductible case:

Open two WSL1 tabs on windows 10
on first tab use ssh command to remote login to a linux server, on remote server issue journalctl -f / tail -f to watch logs
change to second tab

open System Informer, formerly known as Process Hacker, find and double click the WindowsTerminal.exe process, then switch to Performance tab.

intervals with zero cpu usage at the beginning and end of the graph are when text scrolling is happening in the inactive invisible tab
middle interval with cpu usage is when the scrolling is not happening in that tab (before invoking log watching command/after stopping command)

image

@mailinglists35 commented on GitHub (Feb 21, 2023): When you work on fixing this, please also consider the case where the app is not minimized, but it has scrolling activity in inactive tabs. Here's a quick reproductible case: Open two WSL1 tabs on windows 10 on first tab use ssh command to remote login to a linux server, on remote server issue `journalctl -f` / `tail -f` to watch logs change to second tab open System Informer, formerly known as Process Hacker, find and double click the WindowsTerminal.exe process, then switch to Performance tab. intervals with zero cpu usage at the beginning and end of the graph are when text scrolling is happening in the inactive invisible tab middle interval with cpu usage is when the scrolling is not happening in that tab (before invoking log watching command/after stopping command) ![image](https://user-images.githubusercontent.com/2054302/220331133-af5b8798-92ff-4aa3-beb9-7d1984d32886.png)
Author
Owner

@zadjii-msft commented on GitHub (Feb 21, 2023):

Note

Walkthrough

Most of this would be plumbing.

  • Determine if the window was minimized or hidden, or not in IslandWindow. I think we already have a handler for this to minimize to the tray.
  • Plumb that through a WINRT_CALLBACK to AppHost, who would then plumb that to the AppLogic (or TerminalWindow after #14825 merges), and from there into the TerminalPage.
  • In TerminalPage, track that state, and use WalkTree to update each of the TermControls when the minimized state changes
  • Also in TerminalPage / TabManagement.cpp, track when the active tab changes. Each control should only have rendering enabled if (!_windowMinimized) && (tab.IsActive()) (variables / method manes made up in this case)
  • In TermControl, plumb the "rendering active" state into ControlCore
  • Here's where it gets tricky: how exactly do we pause / re-enable the renderer? Do we need to stop the Renderer? The AtlasEngine/DxEngine? Not really sure there. Seems like it'd be easy for the engines to have a flag set and just no-op on any paintframe. 1
  • We'll almost certainly need to do an InvalidateAll / TriggerRedrawAll when re-enabling rendering.

Another method we considered was registering some event in TermControl to auto-detect when a control is added / removed from the UI tree. Turns out this is a Hard problem in WinUI, and probably not the way to go.

Notes about this
  • There's no event that's good for this. Visibility doesn't get changed in this case.
  • There's an internal mail thread titled Quick questions about detecting UI element visibility that might be relevant here.
  • That thread linked https://github.com/microsoft/microsoft-ui-xaml/issues/1900
  • It also recommended code like:
      Element.OnLoaded += () => { LoadedChanged(element); }
      Element.Loaded += () => { LoadedChanged(element); }
    
      void LoadedChanged(element)
      {
          if (element.IsLoaded) { /*do idempotent loaded things*/ }
          else { /*do idempotent unloaded things*/ }
      }
    
    
    • However:

      Aw crud, I see that in the code too ☹ This is more difficult that I realized. From the code, looks like if it’s going from loaded to unloaded, IsLoaded will be correct, but if it’s going from unloaded to loaded, it won’t be true until the Loaded event fires.

    • just check Parent for non-null rather than checking IsLoaded



  1. Someone once noted "Seems like toggling requiresContinuousRedraw in AtlasEngine would be a straightforward path.". I dunno if that's true or not. ↩︎

@zadjii-msft commented on GitHub (Feb 21, 2023): > **Note** > ## Walkthrough Most of this would be plumbing. - [ ] Determine if the window was minimized or hidden, or not in `IslandWindow`. I think we already have a handler for this to minimize to the tray. - [ ] Plumb that through a `WINRT_CALLBACK` to `AppHost`, who would then plumb that to the `AppLogic` (or `TerminalWindow` after #14825 merges), and from there into the `TerminalPage`. - [ ] In `TerminalPage`, track that state, and use `WalkTree` to update each of the TermControls when the minimized state changes - [ ] Also in `TerminalPage` / `TabManagement.cpp`, track when the active tab changes. Each control should only have rendering enabled if `(!_windowMinimized) && (tab.IsActive())` (variables / method manes made up in this case) - [ ] In `TermControl`, plumb the "rendering active" state into `ControlCore` - [ ] Here's where it gets tricky: how exactly do we pause / re-enable the renderer? Do we need to stop the `Renderer`? The `AtlasEngine`/`DxEngine`? Not really sure there. Seems like it'd be easy for the engines to have a flag set and just no-op on any paintframe. [^1] - [ ] We'll almost certainly need to do an `InvalidateAll` / `TriggerRedrawAll` when re-enabling rendering. --- Another method we considered was registering some event in TermControl to auto-detect when a control is added / removed from the UI tree. Turns out this is a **H**ard problem in WinUI, and probably not the way to go. <details> <summary>Notes about this</summary> * There's no event that's _good_ for this. `Visibility` doesn't get changed in this case. * There's an internal mail thread titled **Quick questions about detecting UI element visibility** that might be relevant here. * That thread linked https://github.com/microsoft/microsoft-ui-xaml/issues/1900 * It also recommended code like: ```c# Element.OnLoaded += () => { LoadedChanged(element); } Element.Loaded += () => { LoadedChanged(element); } void LoadedChanged(element) { if (element.IsLoaded) { /*do idempotent loaded things*/ } else { /*do idempotent unloaded things*/ } } ``` * However: > Aw crud, I see that in the code too ☹ This is more difficult that I realized. From the code, looks like if it’s going from loaded to unloaded, IsLoaded will be correct, but if it’s going from unloaded to loaded, it won’t be true until the Loaded event fires. * > just check Parent for non-null rather than checking IsLoaded </details> --- [^1]: Someone once noted _"Seems like toggling requiresContinuousRedraw in AtlasEngine would be a straightforward path."_. I dunno if that's true or not.
Author
Owner

@ChGen commented on GitHub (Feb 3, 2025):

I strongly suggest to consider not only minimised terminals, but also inactive terminal tabs. Currently with both Direct2D and Direct 3D 11 renders it seems that all inactive tabs continue to render and provide frames on system framerate. It's especially noticeable when display is high refresh rate: you'll get GPU load up to 100% and extra CPU load with just a few tabs. Given than more and more laptops and external displays provide at least 90Hz on high DPI, this is huge waste of resources and real battery life.

@ChGen commented on GitHub (Feb 3, 2025): I strongly suggest to consider not only minimised terminals, but also inactive terminal tabs. Currently with both Direct2D and Direct 3D 11 renders it seems that all inactive tabs continue to render and provide frames on system framerate. It's especially noticeable when display is high refresh rate: you'll get GPU load up to 100% and extra CPU load with just a few tabs. Given than more and more laptops and external displays provide at least 90Hz on high DPI, this is huge waste of resources and real battery life.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2791