-
Notifications
You must be signed in to change notification settings - Fork 43
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
Re-implement tree to work with giant structures #40
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This allows dropping metadata after the tree is built which reduces memory consumption.
Since this package is oriented to be as small as possible it is better to avoid ES6-only code. So instead of for..of it is better to use the old for loop.
# Conflicts: # __tests__/FixedSizeTree.spec.tsx # __tests__/VariableSizeTree.spec.tsx # src/Tree.tsx # src/VariableSizeTree.tsx # src/utils.ts
# Conflicts: # __tests__/FixedSizeTree.spec.tsx # __tests__/VariableSizeTree.spec.tsx # src/Tree.tsx
Lodin
force-pushed
the
fix/performance-on-big-data
branch
from
November 4, 2020 16:37
9345263
to
186ad4d
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #11.
Fixes #30.
This is the first PR on the road to version 3. It introduces significant changes (including breaking) for the library.
Common description
The virtual tree system was completely rewritten to fit the new challenges of big tree structures. According to #11 and #30, changing the openness state in trees with about 1 million nodes freeze the UI for several seconds. With this rewrite I'm going to solve the problem. It provides a lot of tools to work with giant trees comfortably.
treeWalker
method only for initial tree building and won't use it for openness state changes.requestIdleCallback
during the build to reduce UI freezing for big trees.requestIdleCallback
as well.Breaking changes
treeWalker
The
treeWalker
function has the completely different shape now.Old
treeWalker
worked for both initial tree building and changing node openness state:Old treeWalker
The new
treeWalker
is only for the tree building. TheTree
component builds and preserves the tree structure internally.New treeWalker
recomputeTree
The
recomputeTree
method has been completely re-worked. Now it is way more powerful than its predecessor, and the main role in this change is played bysubtreeCallback
function that applies to all descendants of the selected node. With it, you can do a lot of things including emulation of the olduseDefaultOpenness
anduseDefaultHeight
options.Old recomputeTree
New recomputeTree
Props
To allow working with
requestIdleCallback
and async actions, the PR introduces the following component properties.async: boolean
This option allows making the tree asynchronous; e.g. you will be able to load the branch data on the node opening. All it does under the hood is preserving the tree state between tree buildings on
treeWalker
update, so the user does not see the tree resetting to the default state when the async action is performed.If it is combined with the
placeholder
option, the tree re-building won't be interrupted by showing the placeholder; it will be shown only at the first time the tree is building.placeholder: ReactNode | null
This property receives any react node that will be displayed instead of a tree during the building process. This option should only be used if the tree building process requires too much time (which means you have a really giant amount of data, e.g. about a million nodes).
Setting this option enables the
requestIdleCallback
under the hood for browsers that support this feature. For other browsers the original scenario is applied; no placeholder will be shown.Using this feature allows avoiding UI freezes; however, it may slightly increase the time spent for the building process.
If you have an asynchronous giant tree and want to use profits of
requestIdleCallback
but don't want placeholder to be shown on the first render (that is probably quite small because all other data will be loaded asynchronously), setplaceholder
tonull
. No placeholder will be shown on the first render but therequestIdleCallback
building will be enabled and allow avoiding freezes on tree re-building when tree becomes bigger.buildingTaskTimeout: number
This option works in tandem with the
placeholder
option. With it, you can set the task timeout for therequestIdleCallback
. ThebuildingTaskTimeout
will be sent directly as therequestIdleCallback
'stimeout
option.