Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't notify a11y event when in ConPTY mode #10537

Merged
3 commits merged into from
Jul 6, 2021

Conversation

skyline75489
Copy link
Collaborator

@skyline75489 skyline75489 commented Jun 30, 2021

Don't notify a11y event when in ConPTY mode

In support of #10528

@skyline75489
Copy link
Collaborator Author

skyline75489 commented Jun 30, 2021

If I'm not mistaken, this only helps with ENABLE_VIRTUAL_TERMINAL_PROCESSING disabled? Because in WriteChars we use:

[[nodiscard]] NTSTATUS WriteChars(...) {
    if (!WI_IsFlagSet(screenInfo.OutputMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING) ||
        !WI_IsFlagSet(screenInfo.OutputMode, ENABLE_PROCESSED_OUTPUT))
    {
        return WriteCharsLegacy(screenInfo,
                                pwchBufferBackupLimit,
                                pwchBuffer,
                                pwchRealUnicode,
                                pcb,
                                pcSpaces,
                                sOriginalXPosition,
                                dwFlags,
                                psScrollY);
    }
    // ...
}

This saves ~7% CPU time:

Before:

image

After:

image

@DHowett
Copy link
Member

DHowett commented Jun 30, 2021

It is also called through the default string handling case for the VT state machine engine, to handle all non-VT strings.

@codeofdusk
Copy link
Contributor

More context on this please? Does it affect UIA? CC @carlos-zamora.

@DHowett
Copy link
Member

DHowett commented Jul 1, 2021

@codeofdusk two important things here:

  1. This is the legacy accessibility eventing system, MSAA
  2. "ConPTY" is the term for when conhost is serving as the "translator" behind another terminal emulator. These events were going nowhere, as the conhost in question is not displaying a window and it is fully expected that the hosting terminal is providing accessibility.

It just wastes CPU time doing accessibility (1) poorly and (2) on a disconnected channel nobody is receiving any information from, ever.

carlos-zamora
carlos-zamora previously approved these changes Jul 1, 2021
@DHowett
Copy link
Member

DHowett commented Jul 1, 2021

I'm not sure about this approach. There's a lot of accessibility event signalling hooked up to this provider, and doing this thing where we just suppress one of the events is just playing "whack-a-mole."

@lhecker -- if we replaced the IAccessibilityThinger with a version that just no-ops for ConPTY... is the cost of a vtable dispatch more expensive than a branch on every output to check if we're in VtIo mode?

Replacing it with a no-op IAccessibilityThing will make it easier to get every single place we would have called it -- cursor updates, scrolling, etc etc etc without having to dig through every bit of code.

@lhecker
Copy link
Member

lhecker commented Jul 1, 2021

@lhecker -- if we replaced the IAccessibilityThinger with a version that just no-ops for ConPTY... is the cost of a vtable dispatch more expensive than a branch on every output to check if we're in VtIo mode?

Branches are probably a bit cheaper, but I doubt by much; we'd have to measure the impact. Since the vtable approach would be more ergonomic I think we should try that first...

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Actually, I suspect that SCREEN_INFORMATION::NotifyAccessibilityEventing on its own is already too expensive, even if we do a new no-op virtual implementation of IAccessibilityNotifier.

It reads the buffer, does some UCS2 crap, and then calls the vtable.

I think we need to do both.

You should move the check here to be inside NotifyAccessibilityEventing and add a new empty/no-op IAccessibilityNotifier that we can use in InteractivityBase.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 1, 2021
@carlos-zamora carlos-zamora dismissed their stale review July 1, 2021 19:51

Sounds like we're changing the approach, so preemptively dismissing my review

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 2, 2021
@skyline75489
Copy link
Collaborator Author

@DHowett I finished the first part and moved the check inside NotifyAccessibilityEventing. I found that I'm not the right person to do the second part: add a new empty/no-op IAccessibilityNotifier and move everything to the no-op one. There's a lot legacy conhost & internal Windows stuff that I don't understand enough to modify. I figure I will just limit this PR to the first part. It's still brings noticeable performance benefit (updated my comment above). That is, in fact, my initial intention for this PR.

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

I'm okay with this if @miniksa is.

@DHowett
Copy link
Member

DHowett commented Jul 6, 2021

@msftbot make sure @miniksa signs off

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jul 6, 2021
@ghost
Copy link

ghost commented Jul 6, 2021

Hello @DHowett!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I'll only merge this pull request if it's approved by @miniksa

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

I'm good but I filed a follow on and will send the second half soon. I can see the route to easy completion on it given my history here.

@ghost ghost merged commit 59239e3 into microsoft:main Jul 6, 2021
DHowett pushed a commit that referenced this pull request Jul 7, 2021
Don't notify a11y event when in ConPTY mode

In support of #10528

(cherry picked from commit 59239e3)
DHowett pushed a commit that referenced this pull request Jul 7, 2021
Don't notify a11y event when in ConPTY mode

In support of #10528

(cherry picked from commit 59239e3)
ghost pushed a commit that referenced this pull request Jul 9, 2021
…PTY mode (#10569)

Change accessibility notifier creation so we do not create one when we're in PTY mode. (Guard all call sites to skip math/event work when the notifier is null.) MSAA events are legacy events that are registered for globally and used by some screen readers to find content in the conhost window. The PTY mode is not responsible for hosting the display content or input window, so it makes sense for it to not broadcast these events and delegate the accessibility requirement to the connected terminal.

## References
- #10537 

## PR Checklist
* [x] Closes #10568
* [x] I work here
* [x] Manual test launches passed.
DHowett pushed a commit that referenced this pull request Jul 12, 2021
…PTY mode (#10569)

Change accessibility notifier creation so we do not create one when we're in PTY mode. (Guard all call sites to skip math/event work when the notifier is null.) MSAA events are legacy events that are registered for globally and used by some screen readers to find content in the conhost window. The PTY mode is not responsible for hosting the display content or input window, so it makes sense for it to not broadcast these events and delegate the accessibility requirement to the connected terminal.

## References
- #10537

## PR Checklist
* [x] Closes #10568
* [x] I work here
* [x] Manual test launches passed.

(cherry picked from commit 91b454a)
@ghost
Copy link

ghost commented Jul 14, 2021

🎉Windows Terminal v1.9.1942.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Jul 14, 2021

🎉Windows Terminal Preview v1.10.1933.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants