Skip to content

Conversation

@DHowett
Copy link
Member

@DHowett DHowett commented Jul 30, 2025

Windows 11 uses some additional signals to determine what the user cares
about and give it a bit of a QoS boost. One of those signals is whether
it is associated with a window that is in the foreground or which has
input focus.

Association today takes two forms:

  • Process has a window which is in the foreground or which has input
    focus
  • Process has a parent that meets the above criterion.

Console applications that are spawned "inside" terminal by handoff do
not fall into either bucket. They don't have a window. Their parent is
dllhost or explorer, who is definitely not in focus.

We are piloting a new API that allows us to associate those processes
with Terminal's window.

When Terminal is in focus, it will attach every process from the active
tab to its QoS group. This means that whatever is running in that tab
is put into the "foreground" bucket, and everything running in other
background tabs is not.

When Terminal is out of focus, it attaches every process to its QoS
group. This ensures that they all go into the "background" bucket
together, following the window.

@DHowett DHowett changed the title WIP: Use the new Ge+ API to propagate Terminal's QoS priority to its "friends" WIP: Use the new Ge+ API to propagate Terminal things to its "friends" Jul 30, 2025
commit 8fbd544
Author: Dustin L. Howett <dustin@howett.net>
Date:   Wed Jun 4 18:12:19 2025 -0500

    Uncommentary

commit 8c08e0e
Author: Dustin L. Howett <dustin@howett.net>
Date:   Wed Jun 4 18:12:02 2025 -0500

    Commentary

commit b07bc3a
Merge: b3615d5 155d8a9
Author: Dustin L. Howett <dustin@howett.net>
Date:   Wed Jun 4 18:04:14 2025 -0500

    Merge remote-tracking branch 'origin/main' into dev/duhowett/propagate-priority

commit b3615d5
Author: Dustin Howett <duhowett@microsoft.com>
Date:   Tue Aug 13 14:33:32 2024 -0500

    yott yeet

commit 596a17b
Author: Dustin Howett <duhowett@microsoft.com>
Date:   Tue Aug 13 14:21:18 2024 -0500

    Yeet yott

Ensure that we have the right rights

Move to TerminalThemeHelpers

(cherry picked from commit 9670a53f8b92f08e67034704edd247a1f954643d)
@DHowett DHowett force-pushed the dev/duhowett/propagate-priority branch from 7d806cb to d3d1cff Compare August 11, 2025 20:21
@DHowett DHowett changed the title WIP: Use the new Ge+ API to propagate Terminal things to its "friends" Use a new API to propagate foreground state to child processes Aug 11, 2025
@DHowett DHowett marked this pull request as ready for review August 11, 2025 22:23
_UpdateBackground(profile);
}

_adjustProcessPriorityGivenFocusState(_activated);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to debounce it? Not sure what the API cost is...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Happy to do it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just loop it 1000 times and measure how long it takes. Do you happen to already have a debug build ready locally? I'd just do:

const auto beg = std::chron::high_resolution_clock::now();
for (int i = 0; i < 1000; ++i) _adjustProcessPriorityGivenFocusState(_activated);
const auto end = std::chron::high_resolution_clock::now();
const auto dur = std::chrono::duration<double>(end - beg).count();
OutputDebugStringA(fmt::format("{} ns/op\n", dur * 1e9 / 1000.0).c_str());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr the cost is in the order of 10us/op, as it crosses a syscall (and this is the typical cost).

@DHowett DHowett enabled auto-merge (squash) August 12, 2025 23:42
@DHowett DHowett merged commit 0d23624 into main Aug 13, 2025
17 of 19 checks passed
@DHowett DHowett deleted the dev/duhowett/propagate-priority branch August 13, 2025 00:09
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.23 Servicing Pipeline Aug 21, 2025
DHowett added a commit that referenced this pull request Aug 21, 2025
Windows 11 uses some additional signals to determine what the user cares
about and give it a bit of a QoS boost. One of those signals is whether
it is associated with a window that is in the foreground or which has
input focus.

Association today takes two forms:
- Process has a window which is in the foreground or which has input
  focus
- Process has a *parent* that meets the above criterion.

Console applications that are spawned "inside" terminal by handoff do
not fall into either bucket. They don't have a window. Their parent is
`dllhost` or `explorer`, who is definitely not in focus.

We are piloting a new API that allows us to associate those processes
with Terminal's window.

When Terminal is in focus, it will attach every process from the active
tab to its QoS group. This means that whatever is running in that tab
is put into the "foreground" bucket, and everything running in other
background tabs is not.

When Terminal is out of focus, it attaches every process to its QoS
group. This ensures that they all go into the "background" bucket
together, following the window.

(cherry picked from commit 0d23624)
Service-Card-Id: PVTI_lADOAF3p4s4Axadtzgdh6-Q
Service-Version: 1.23
@DHowett DHowett moved this from Cherry Picked to Shipped in 1.23 Servicing Pipeline Sep 5, 2025
DHowett pushed a commit that referenced this pull request Sep 16, 2025
You can now create throttled functions which trigger both on the leading
and trailing edge. This was then also ported to `ThrottledFunc` for
`DispatcherQueue`s and used for title/taskbar updates.

Closes #19188

* In CMD run:
  ```batch
  FOR /L %N IN () DO @echo %time%
  ```
* Doesn't hang the UI ✅

SERVICE NOTES
This replays part of #19192 to make it compatible with throttled_func.

(cherry picked from commit dbf740c)
Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgdI2TQ PVTI_lADOAF3p4s4AxadtzgdSMv0
Service-Version: 1.23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants