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

Tool: fix SelectFromList on large list #2562

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jorisvandermeulen
Copy link
Contributor

@jorisvandermeulen jorisvandermeulen commented Feb 4, 2025

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:

  • Code follows the PEP 8 style guide.
  • Code has been formatted with Black using the command:
    pipenv run black {source_file_or_directory}
  • Changes are tested and verified to work as expected.

Related Issues

If applicable, link the issues resolved by this pull request:


Thank you for contributing to pyRevit! 🎉

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
Copy link
Contributor

devloai bot commented Feb 4, 2025

Automatic code review is enabled for this repository. Reviewing this PR now.

Copy link
Contributor

@devloai devloai bot left a 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}"
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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"/>

@jmcouffin jmcouffin changed the title Update SelectFromList.xaml Tool: fix SelectFromList on large list Feb 4, 2025
@jmcouffin
Copy link
Contributor

@jorisvandermeulen ok, just say the word, then I'll merge the PR

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.

2 participants