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

perf(treeData): decrease Tree Grid expandAll/collapseAll time by 40x #1681

Merged
merged 2 commits into from
Sep 21, 2024

Conversation

ghiscoding
Copy link
Owner

@ghiscoding ghiscoding commented Sep 15, 2024

Another perf optimization that is probably O(n square) if not more.

When collapsing/expanding items in the grid, we also need to update the hierarchical (tree) dataset and the previous code was searching for the item in the tree and then was toggling its collapse prop. When we have a single item that we collapse, searching in the tree is relatively quick, but when we toggle thousand of items and we search them one-by-one then this becomes extremely costly to execute (search+toggle for every row). What we can do to decrease the time is to keep doing the toggle of the collapse prop on the flat array BUT instead of searching each item in the tree, we can simply recreate the hierarchical (tree) only once and we're done (40x decrease as shown below).


Perf logs for Example 5 with 25k items

Before (expand all, collapse all)

tree collapse/expand: 2572.123779296875 ms
tree collapse/expand: 2432.596923828125 ms

After (expand all, collapse all)

tree collapse/expand: 65.237060546875 ms
tree collapse/expand: 57.0859375 ms

brave_bpGVGeKDmc

Copy link

stackblitz bot commented Sep 15, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

codecov bot commented Sep 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.8%. Comparing base (beae104) to head (62d342a).
Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1681     +/-   ##
========================================
+ Coverage    99.8%   99.8%   +0.1%     
========================================
  Files         187     187             
  Lines       31093   31097      +4     
  Branches     9787    9790      +3     
========================================
+ Hits        31004   31008      +4     
  Misses         89      89             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ghiscoding ghiscoding changed the title perf(treeData): huge time decrease to expandAll/collapseAll tree grid perf(treeData): decrease Tree Grid expandAll/collapseAll by 400x Sep 15, 2024
@ghiscoding ghiscoding changed the title perf(treeData): decrease Tree Grid expandAll/collapseAll by 400x perf(treeData): decrease Tree Grid expandAll/collapseAll by 40x Sep 15, 2024
@ghiscoding ghiscoding changed the title perf(treeData): decrease Tree Grid expandAll/collapseAll by 40x perf(treeData): decrease Tree Grid expandAll/collapseAll time by 40x Sep 15, 2024
@ghiscoding ghiscoding merged commit 4eea035 into master Sep 21, 2024
16 checks passed
@ghiscoding ghiscoding deleted the perf/tree-expand-collapse-all branch September 21, 2024 04:45
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.

1 participant