Defer UIA accessibility provider initialization until requested
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_TextPatternIdandUIA_TextPattern2Idfor text providersUIA_AnnotationPatternIdfor annotation providers
Changes Made
- Removed eager initialization from constructor (lines 34-45)
- Added lazy initialization in
GetPatternProviderwith null checks to prevent multiple creation - Added required include for
CompositionTextProvider.h - 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.
/azp run
Azure Pipelines successfully started running 2 pipeline(s).
@copilot whenever the build results states: ERROR: Change files are needed! you should run yarn change at the root of the repository.
@copilot whenever the build results states:
ERROR: Change files are needed!you should runyarn changeat the root of the repository.
Added change file for beachball version management in commit d927cd0.
/azp run
Azure Pipelines successfully started running 2 pipeline(s).
@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.
@copilot after running yarn install, run yarn format to update the formatting in the PR.
@copilot after running
yarn install, runyarn formatto 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:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
/azp run
Azure Pipelines successfully started running 2 pipeline(s).
@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.