-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Tool: fix SelectFromList on large list #2562
base: develop
Are you sure you want to change the base?
Tool: fix SelectFromList on large list #2562
Conversation
On large lists (2200 items) 7seconds to 2seconds 3.5 faster / 71% faster As described on forum https://discourse.pyrevitlabs.io/t/faster-selectfromlist/8582
Automatic code review is enabled for this repository. Reviewing this PR now. |
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.
Great performance optimization using WPF virtualization! The changes look clean and effectively reduce rendering time for large lists by 71%. I've added one suggestion for fine-tuning the virtualization cache settings that could further improve scrolling smoothness.
@devloai optimize-virtualization - Let me know if you'd like me to implement the suggested virtualization cache settings.
@@ -130,7 +130,10 @@ | |||
HorizontalContentAlignment="Stretch" | |||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" | |||
ItemTemplate="{DynamicResource ItemContainerTemplate}" | |||
ItemsPanel="{DynamicResource ItemsPanelTemplate}" /> | |||
ItemsPanel="{DynamicResource ItemsPanelTemplate}" |
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.
Consider adding VirtualizingStackPanel.CacheLength
and VirtualizingStackPanel.CacheLengthUnit
properties to fine-tune the virtualization behavior. This can help balance between memory usage and scrolling performance. Here's the recommended configuration:
<ListView ...
ItemsPanel="{DynamicResource ItemsPanelTemplate}"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
VirtualizingStackPanel.CacheLength="5"
VirtualizingStackPanel.CacheLengthUnit="Page"
ScrollViewer.CanContentScroll="True"
... />
This will cache 5 pages worth of items, providing smoother scrolling while still maintaining good memory efficiency.
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.
@jorisvandermeulen can you check if this improves the performances?
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 will check that.
I believe the default value for VirtualizingStackPanel.CacheLengthUnit is "Page" but obviously it's good to explicitly set the value.
The length default value is 1. So 1 'page' before / after is kept in memory. Increasing that value, increase the memory usage but smoother scrolling experience.
Let me get back to this.
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.
No real time improvement. Smoother scrolling ... a little bit. Can't say I notice it right away.
Tested CacheLength 1, 2, 5 and even 10.
Json items tested: 2200
Time to load: "Function 'searchandload' executed in 0.960587 seconds." (click to popup show and manually click close as fast as possible).
So perhaps 2 is a good value.
<ListView x:Name="list_lb" Grid.Column="0" MouseDoubleClick="button_select" SelectionChanged="selected_item_changed" SelectionMode="Extended" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemTemplate="{DynamicResource ItemContainerTemplate}" ItemsPanel="{DynamicResource ItemsPanelTemplate}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ScrollViewer.CanContentScroll="True" VirtualizingStackPanel.CacheLength="2" VirtualizingStackPanel.CacheLengthUnit="Page"/>
@jorisvandermeulen ok, just say the word, then I'll merge the PR |
Tool: fix SelectFromList on large list
Description
On large lists (2200 items)
7seconds to 2seconds
3.5 faster / 71% faster
As described on forum
https://discourse.pyrevitlabs.io/t/faster-selectfromlist/8582
Checklist
Before submitting your pull request, ensure the following requirements are met:
Related Issues
If applicable, link the issues resolved by this pull request:
Thank you for contributing to pyRevit! 🎉