ghiscoding / slickgrid-universal

Slickgrid-Universal is a monorepo which includes all Editors, Filters, Extensions, Services related to SlickGrid usage and is also Framework Agnostic
https://ghiscoding.github.io/slickgrid-universal/
Other
90 stars 29 forks source link

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

Closed ghiscoding closed 2 months ago

ghiscoding commented 2 months ago

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

stackblitz[bot] commented 2 months ago

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

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.