Commit 84a7d57
committed
perf(react-tree): avoid processing hidden subtrees
This PR makes FlatTree support large data sets with good performance as
long as most items are not rendered at once, which should be the common
case.
This is done by optimizing two key functions.
The first deals with multiselect state, and simply batches all updates
instead of calling `ImmutableMap.set()` in a loop over the entire
subtree, which had a big performance impact due to each call copying
the entire Map.
When toggling the checkbox for a branch with a 2800 item subtree, the
delay went from an unusable 1800 ms to 8 ms.
The second fix is to avoid processing of invisible subtrees when
generating the visible tree based on open items.
This one requires a larger tree to be noticeable, but at 35k items, the
generator took 600 ms before and 10 ms after the fix.
An easy way to test is to modify the story "TreeSelection", changing the
`items` array so that it's generated with a loop.1 parent f4a83d0 commit 84a7d57
File tree
3 files changed
+70
-19
lines changed- change
- packages/react-components/react-tree/library/src
- components/FlatTree
- utils
3 files changed
+70
-19
lines changedLines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 32 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
44 | 56 | | |
45 | | - | |
| 57 | + | |
46 | 58 | | |
47 | | - | |
48 | 59 | | |
| 60 | + | |
| 61 | + | |
49 | 62 | | |
50 | | - | |
51 | | - | |
| 63 | + | |
| 64 | + | |
52 | 65 | | |
53 | | - | |
| 66 | + | |
54 | 67 | | |
55 | 68 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
60 | 76 | | |
61 | 77 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
65 | 81 | | |
66 | | - | |
| 82 | + | |
67 | 83 | | |
68 | | - | |
69 | 84 | | |
70 | 85 | | |
| 86 | + | |
| 87 | + | |
71 | 88 | | |
72 | 89 | | |
73 | 90 | | |
| |||
Lines changed: 31 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
268 | 295 | | |
269 | 296 | | |
270 | 297 | | |
| |||
0 commit comments