Skip to content

Defer UIA accessibility provider initialization until requested #14756

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 10, 2025

Summary

This PR optimizes the initialization of UIA (UI Automation) accessibility providers by deferring their creation until they are actually requested by the UIA agent, rather than eagerly creating them in the constructor.

Problem

Previously, CompositionDynamicAutomationProvider was creating m_textProvider and m_annotationProvider instances in its constructor regardless of whether the UIA agent would ever request these patterns. This resulted in unnecessary object creation and initialization overhead for accessibility scenarios where these specific patterns weren't used.

Solution

Moved the provider initialization from the constructor to the GetPatternProvider method, where they are created lazily only when the UIA agent requests the specific pattern IDs:

  • UIA_TextPatternId and UIA_TextPattern2Id for text providers
  • UIA_AnnotationPatternId for annotation providers

Changes Made

  1. Removed eager initialization from constructor (lines 34-45)
  2. Added lazy initialization in GetPatternProvider with null checks to prevent multiple creation
  3. Added required include for CompositionTextProvider.h
  4. Preserved all original logic and conditions for when providers should be created
// Before: Always created in constructor
if (strongView.try_as<WindowsTextInputComponentView>() || 
    strongView.try_as<ParagraphComponentView>()) {
  m_textProvider = winrt::make<CompositionTextProvider>(...);
}

// After: Created only when requested
if (patternId == UIA_TextPatternId && /* same conditions */) {
  if (!m_textProvider) {
    m_textProvider = winrt::make<CompositionTextProvider>(...);
  }
  m_textProvider.as<IUnknown>().copy_to(pRetVal);
}

Performance Impact

  • Reduces initialization overhead when UIA patterns are not requested
  • Maintains full functionality while improving performance
  • No breaking changes to the public API

Fixes #14644.

@Copilot Copilot AI changed the title [WIP] Defer the initialization of accessibility providers Defer UIA accessibility provider initialization until requested Jun 10, 2025
@Copilot Copilot AI requested a review from chrisglein June 10, 2025 17:43
Copilot finished work on behalf of chrisglein June 10, 2025 17:44
@acoates-ms acoates-ms marked this pull request as ready for review June 10, 2025 18:28
@acoates-ms acoates-ms requested a review from a team as a code owner June 10, 2025 18:28
@acoates-ms
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@dannyvv
Copy link
Member

dannyvv commented Jun 10, 2025

@copilot whenever the build results states: ERROR: Change files are needed! you should run yarn change at the root of the repository.

Copy link
Author

Copilot AI commented Jun 10, 2025

@copilot whenever the build results states: ERROR: Change files are needed! you should run yarn change at the root of the repository.

Added change file for beachball version management in commit d927cd0.

Copilot finished work on behalf of dannyvv June 10, 2025 18:41
@acoates-ms
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@chiaramooney
Copy link
Contributor

@chrisglein be careful before this change is merged. Someone should validate that Narrator still works as expected. We've had issues with accessibilityprovider initialization optimization breaking Narrator in the past.

@acoates-ms
Copy link
Contributor

@copilot after running yarn install, run yarn format to update the formatting in the PR.

Copy link
Author

Copilot AI commented Jun 10, 2025

@copilot after running yarn install, run yarn format to update the formatting in the PR.

Formatting applied with clang-format to fix spacing issues in commit 74cbd54.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • googlechromelabs.github.io
    • Triggering command: /usr/local/bin/node install.mjs (dns block)
  • https://storage.googleapis.com/chrome-for-testing-public/130.0.6723.116/linux64/chrome-headless-shell-linux64.zip
    • Triggering command: /usr/local/bin/node install.mjs (http block)
  • https://storage.googleapis.com/chrome-for-testing-public/130.0.6723.116/linux64/chrome-linux64.zip
    • Triggering command: /usr/local/bin/node install.mjs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of acoates-ms June 10, 2025 21:34
@acoates-ms
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@chrisglein
Copy link
Member

@chrisglein be careful before this change is merged. Someone should validate that Narrator still works as expected. We've had issues with accessibilityprovider initialization optimization breaking Narrator in the past.

Oh definitely. This is our first try of the Copilot agent and we should treat this with high scrutiny. It obviously can't do any manual testing, so anything not covered by automation needs us to manually validate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Defer the initialization of accessibility providers
5 participants