Skip to content

Conversation

@toerndev
Copy link
Contributor

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.

@toerndev toerndev force-pushed the master branch 3 times, most recently from 2629ffc to 5254266 Compare September 24, 2025 07:20
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.
@toerndev
Copy link
Contributor Author

@microsoft-github-policy-service agree

@toerndev toerndev marked this pull request as ready for review September 24, 2025 07:27
@toerndev toerndev requested a review from a team as a code owner September 24, 2025 07:27
Copy link
Contributor

@bsunderhus bsunderhus left a comment

Choose a reason for hiding this comment

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

LGM, next time let's open one PR per modification here, those two modifications are not related, but since both are small changes I don't mind in this case ✅ Thanks for the contribution!

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-components
react-components: Button, FluentProvider & webLightTheme
68.539 kB
19.777 kB
68.796 kB
19.903 kB
257 B
126 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
235.521 kB
68.269 kB
236.635 kB
68.578 kB
1.114 kB
309 B
react-components
react-components: FluentProvider & webLightTheme
43.373 kB
14.138 kB
43.63 kB
14.257 kB
257 B
119 B
react-components
react-components: entire library
1.277 MB
321.083 kB
1.279 MB
321.419 kB
1.306 kB
336 B
react-timepicker-compat
TimePicker
108.795 kB
35.981 kB
109.931 kB
36.336 kB
1.136 kB
355 B
react-tree
FlatTree
147.93 kB
42.339 kB
149.277 kB
42.702 kB
1.347 kB
363 B
react-tree
PersonaFlatTree
148.688 kB
42.47 kB
150.035 kB
42.83 kB
1.347 kB
360 B
react-tree
PersonaTree
144.953 kB
41.334 kB
146.096 kB
41.652 kB
1.143 kB
318 B
react-tree
Tree
144.201 kB
41.218 kB
145.346 kB
41.528 kB
1.145 kB
310 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-portal-compat
PortalCompatProvider
8.386 kB
2.624 kB
🤖 This report was generated against b41f392051f3538ced36c51888a94a2af6fe2f5a

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

Pull request demo site: URL

@bsunderhus bsunderhus merged commit 3f58fe3 into microsoft:master Nov 10, 2025
13 checks passed
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