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

Add methods to expand/collapse multiple levels of items without a performance penalty. #273

Merged
merged 8 commits into from
Apr 1, 2024

Conversation

grokys
Copy link
Member

@grokys grokys commented Mar 14, 2024

Previously the only way to e.g. expand all items in a hierarchical TreeDataGrid was to expand each item one by one. This was very slow as after each expansion the flattened list of rows needed to be recalculated.

Added the follow methods which speed this up:

  • ExpandAll: to expand all rows recursively
  • ExpandCollapseRecursive: to expand or collapse all rows recursively based on a predicate
  • CollapseAll: to collapse all rows recursively

grokys added 6 commits March 8, 2024 15:10
Previously expanding many nodes was expensive as the flattened list was being recalculated with each expansion. Add a recursive version which recalculates the flattened list at the end.
Previously reassigning hierarchical items was expensive as the flattened list was being recalculated with each row disposal. Ignore collection changes while the rows are being disposed and recalculate the flattened rows at the end.
Failing when sorting enabled.
@danipen danipen self-requested a review March 14, 2024 16:10
Copy link
Collaborator

@danipen danipen left a comment

Choose a reason for hiding this comment

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

The new changes are performing incredibly well, @grokys rocks!

@@ -72,6 +74,33 @@ public void Expand(IndexPath index)
}
}

internal void ExpandRecursive(Func<TModel, bool>? filter)
{
static void Expand(IReadOnlyList<HierarchicalRow<TModel>> rows, Func<TModel, bool>? filter)
Copy link
Collaborator

@danipen danipen Mar 14, 2024

Choose a reason for hiding this comment

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

I'm wondering if it would be interesting to expose the method Expand for a given row. We probably need to expand some nodes inside the hierarchy, so probably having this public should be interesting.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's already exposed in the source which is where it should be called from. I think it was probably a mistake to expose the other expand and collapse methods in HirearchicalRow (to limit API surface) so I didn't want to expose any more than was necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I think I understand what you're saying now. Yes, if you already have a row instance then I guess it could be useful. I can expose them if it would be useful to you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this PR is accepted, we won't need it. But I still think it's a useful API for others if one needs to recursively expand a non-root node :-).

grokys added 2 commits March 15, 2024 12:37
It didn't make much sense that returning `true` from the `ExpandRecursive` predicate caused the node to be expanded, but returning `false` didn't cause it to be collapsed. This API allows one to expand and collapse from the same method.
@alvaro-berruezo-unity3d
Copy link

Tested the new methods to expand/collapse a large number of rows (~60k) with a good amount of depth. The methods work as expected and the performance is greatly improved

@danipen danipen merged commit c7c178c into master Apr 1, 2024
5 checks passed
@danipen danipen deleted the fixes/expand-collapse-perf branch April 1, 2024 09:43
@neondev9
Copy link

neondev9 commented May 3, 2024

Included in recent 11.0.10.
Thanks a lot for this very useful methods.

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.

4 participants