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

[PowerRename] Handle many items w/o crashing and OOM #26761

Merged
merged 11 commits into from
Jul 13, 2023

Conversation

yuyoyuppe
Copy link
Contributor

@yuyoyuppe yuyoyuppe commented Jun 9, 2023

Summary of the Pull Request

PowerRename.100K.ListView.mp4
  • Introduce proxy collection for shell items
  • Make sure virtualization works for ListView
  • Disable AnimatedIcon for CheckBox

PR Checklist

Detailed Description of the Pull Request / Additional comments

  1. Isolating the issue showed that using the following XAML instead of the current PowerRename's ExplorerItems was still crashing when scrolling with 1K+ items:
        <ListView.ItemTemplate>
            <DataTemplate>
                <CheckBox />
            </DataTemplate>
        </ListView.ItemTemplate>

So, simply using WinUI's CheckBox causes the app to crash, as was noted previously. Using a DataTemplate with a CheckBox instead of wrapping it in a UserControl makes the behavior much better, but it's still possible to crash it.

Another issue is that the scrolling starts to slow down and end up unusable. Sampling the call stack shows it happens somewhere in the DirectComposition layer:

>	Microsoft::UI::Composition::AnimationBindingManager::UnregisterAllAnimationTargets()	Unknown
 	Microsoft::UI::Composition::Visual::Destroy(void)	Unknown
 	Microsoft::WRL2::ContextRuntimeClass::ProcessDestroyWorkflow(bool,bool *)	Unknown
 	Microsoft::UI::Composition::VisualCommon::CleanUpAllChildren(void)	Unknown
 	Microsoft::UI::Composition::Visual::Destroy(void)	Unknown

Inspecting Live Visual Tree has shown that UI virtualization is also active: the number of ListViewItems doesn't grow beyond a certain number. Explicitly setting VirtualizingStackPanel as a ListView.ItemsPanel didn't make a difference.

  1. By copying the style directly into PowerRename App.xaml's resources it's evident that the element that's causing that is <animatedVisuals:AnimatedAcceptVisualSource /> of AnimatedIcon, i.e. the check mark icon.

Looking at the docs, we can find the line responsible for not using animation, but it doesn't make a difference when turning off the animations (Accessibility -> Visual Effects -> Animation effects). I haven't found a way to force Fallback animation, so I've removed the AnimatedIcon by overriding CheckBox's Style and filed an issue in WinUI repo.

  1. Now, trying to add many items using DEBUG_BENCHMARK_100K_ENTRIES resulted in an OOM on my system, because each element of vec<ExplorerItem> is a UserControl, thus ExplorerItemsSource and ExplorerItemViewModel were implemented to support data virtualization and is essentially a proxy to IPowerRenameManager's items.

  2. For some reason, x:Bind doesn't work in the context of DataTemplate when binding ExplorerItem's properties to ExplorerItemViewModel's properties with the same name, so I've added VM suffices to the property names accordingly.

  3. Using parallel std::sort increased startup performance from 80seconds to 30seconds.

  4. OnAdded and OnUpdated events are no longer needed anymore, as well as ExplorerItemsMap.

Validation Steps Performed

  • 100K test
  • full checklist

@yuyoyuppe yuyoyuppe force-pushed the issue_18478 branch 3 times, most recently from 0c6864f to 68cc489 Compare June 27, 2023 13:05
@yuyoyuppe yuyoyuppe force-pushed the issue_18478 branch 5 times, most recently from 954ef5a to a08c29c Compare July 4, 2023 11:05
@yuyoyuppe yuyoyuppe marked this pull request as ready for review July 4, 2023 11:06
@yuyoyuppe
Copy link
Contributor Author

Ready for review. Supports up to 100K entries on my machine w/o issues.

Copy link
Collaborator

@stefansjfw stefansjfw left a comment

Choose a reason for hiding this comment

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

I still see issues on "Only show items that will be renamed" view on scrolling. All renamable items end up in the same depth, i.e. folders are lost

@yuyoyuppe
Copy link
Contributor Author

Ready for review. After internal discussion, we've decided to move forward with Standard VirtualizationMode for now.

Copy link
Collaborator

@SeraphimaZykova SeraphimaZykova left a comment

Choose a reason for hiding this comment

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

Tested on ARM, it works stable and not crashing on a significant amount of files.

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

After starting from a clean start (Delete "%localappdata%\Microsoft\PowerToys"), it shows no files when selecting a 10000 file folder I was testing with:
image
Can we default to showing some files as the default, like before? This will be a bad default experience as users won't understand what's going on.

@stefansjfw
Copy link
Collaborator

After starting from a clean start (Delete "%localappdata%\Microsoft\PowerToys"), it shows no files when selecting a 10000 file folder I was testing with: image Can we default to showing some files as the default, like before? This will be a bad default experience as users won't understand what's going on.

Was it with DEBUG_BENCHMARK_100K_ENTRIES enabled or triggering from context menu?

@stefansjfw
Copy link
Collaborator

After starting from a clean start (Delete "%localappdata%\Microsoft\PowerToys"), it shows no files when selecting a 10000 file folder I was testing with: image Can we default to showing some files as the default, like before? This will be a bad default experience as users won't understand what's going on.

Was it with DEBUG_BENCHMARK_100K_ENTRIES enabled or triggering from context menu?

yeah, I can reproduce this after installing powertoys

@yuyoyuppe
Copy link
Contributor Author

@jaimecbernardo nice catch, fixed!

@yuyoyuppe yuyoyuppe requested a review from stefansjfw July 13, 2023 12:29
Copy link
Collaborator

@stefansjfw stefansjfw left a comment

Choose a reason for hiding this comment

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

Overall, it looks good. There are few things discussed privately that could be investigated to improve performance. Ok to have those as separate PRs.

For this one, let's just fix showing directory structure of Show only files that will be renamed view.

@yuyoyuppe yuyoyuppe requested a review from stefansjfw July 13, 2023 14:04
Copy link
Collaborator

@stefansjfw stefansjfw left a comment

Choose a reason for hiding this comment

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

very nice! :)

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

Tested and works as expected. Thank you!

Copy link
Collaborator

@SeraphimaZykova SeraphimaZykova left a comment

Choose a reason for hiding this comment

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

Tested, works nicely!

@yuyoyuppe yuyoyuppe merged commit 53e104e into microsoft:main Jul 13, 2023
@yuyoyuppe yuyoyuppe deleted the issue_18478 branch July 13, 2023 16:42
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.

5 participants