-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve UIA Provider Cleanup Logic for Virtual ListView Items #13953
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
base: main
Are you sure you want to change the base?
Improve UIA Provider Cleanup Logic for Virtual ListView Items #13953
Conversation
e987626
to
daf7e8d
Compare
daf7e8d
to
c0e5c79
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13953 +/- ##
===================================================
+ Coverage 77.15093% 77.15120% +0.00027%
===================================================
Files 3276 3276
Lines 645116 645141 +25
Branches 47705 47709 +4
===================================================
+ Hits 497713 497734 +21
+ Misses 143716 143712 -4
- Partials 3687 3695 +8
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, with this approach, we are "unvirtualize" ListView items and prevent them from being GC-collected. Let's discuss this and make sure, I am not missing anything.
@KlausLoeffelmann I updated the PR, please review it again. Added _uiaAccessedIndices to track only the indices accessed by UIA in virtual mode, _uiaAccessedIndices stores only integer indices, not ListViewItem objects. Since there is no strong reference to the actual items, the GC can still reclaim them when they are no longer used. |
Fixes #13922
Root Cause
When
ListView.VirtualMode = true
, the current implementation ofReleaseUiaProvider()
iterates over all indices (Items.Count) and callsItems.GetItemByIndex()
.This triggers
OnRetrieveVirtualItem
for every index, forcing creation of all virtual items even if they were never displayed or accessed.Result in:
Severe performance degradation for large virtual lists (e.g., tens of thousands of items).
High memory pressure due to unnecessary ListViewItem instantiation.
UI freeze during control disposal.
Proposed changes
This PR improves the cleanup logic for UI Automation (UIA) providers in ListView when operating in
VirtualMode = true
. Specifically:_uiaAccessedIndices
tracking mechanism to record only the indices of items whoseAccessibilityObject
was created by UIA.ReleaseUiaProvider
to selectively release UIA providers only for accessed items, avoiding full traversal ofVirtualListSize
and improving performance.NotifyUiaCreated
is called duringAccessibilityObject
creation to maintain accurate tracking.RetrieveVirtualItem
during cleanup, which previously caused unnecessary item creation and severe performance degradation in large virtual lists.Customer Impact
Regression?
Risk
Screenshots
Before
When closing the form containing the ListView (in virtual mode), followed by closing the main form, the application experienced a noticeable delay.
BeforeChanges.mp4
After
When closing the form containing the ListView (in virtual mode), and subsequently closing the main form, the main form closes immediately with no noticeable delay.
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow