-
Notifications
You must be signed in to change notification settings - Fork 171
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
Improved buildTree
.
#6325
Merged
Merged
Improved buildTree
.
#6325
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
- Reworked `buildTree_MUTATE` to build the tree from the root downwards, combining it with some of the logic taken from `getChildrenPaths`. - Further improvement to `isDescendantOf` replacing the previous implementation. - `getReorderedPaths` now avoids a lot of repeated logic for checking the element type.
seanparsons
requested review from
gbalint,
Rheeseyb,
ruggi,
liady and
bkrmendy
September 5, 2024 16:51
#14182 Bundle Size — 62.62MiB (~+0.01%).e0d58e3(current) vs 916e8b9 master#14176(baseline) Warning Bundle contains 70 duplicate packages – View duplicate packages Bundle metrics
|
Current #14182 |
Baseline #14176 |
|
---|---|---|
Initial JS | 45.74MiB (~+0.01% ) |
45.74MiB |
Initial CSS | 0B |
0B |
Cache Invalidation | 21.67% |
21.65% |
Chunks | 30 |
30 |
Assets | 33 |
33 |
Modules | 4385 |
4385 |
Duplicate Modules | 523 |
523 |
Duplicate Code | 31.65% |
31.65% |
Packages | 472 |
472 |
Duplicate Packages | 70 |
70 |
Bundle size by type 2 changes
1 regression
1 improvement
Current #14182 |
Baseline #14176 |
|
---|---|---|
JS | 62.61MiB (~+0.01% ) |
62.6MiB |
HTML | 11.12KiB (-0.32% ) |
11.16KiB |
Bundle analysis report Branch performance/improved-buildtree Project dashboard
Generated by RelativeCI Documentation Report issue
- Broke apart `ElementPathTree.children` into two separate fields to make for easier ordering. - Added `getElementPathTreeChildren` and `forEachElementPathTreeChild` utility functions. - `buildTree_MUTATE` now adds to the two different children fields based on the element path representing inner children over property children. - `getReorderedIndexInPaths` further reworked to handle shifting by the siblings. - Fixed some tests that had expressions incorrectly ordered.
gbalint
reviewed
Sep 10, 2024
gbalint
reviewed
Sep 10, 2024
gbalint
reviewed
Sep 10, 2024
gbalint
reviewed
Sep 10, 2024
gbalint
reviewed
Sep 10, 2024
gbalint
approved these changes
Sep 10, 2024
Rheeseyb
reviewed
Sep 11, 2024
Rheeseyb
reviewed
Sep 11, 2024
Rheeseyb
approved these changes
Sep 11, 2024
liady
pushed a commit
that referenced
this pull request
Dec 13, 2024
- Reworked `buildTree_MUTATE` to build the tree from the root downwards, combining it with some of the logic taken from `getChildrenPaths`. - Further improvement to `isDescendantOf` replacing the previous implementation. - `getReorderedPaths` now avoids a lot of repeated logic for checking the element type. - Broke apart `ElementPathTree.children` into two separate fields to make for easier ordering. - Added `getElementPathTreeChildren` and `forEachElementPathTreeChild` utility functions. - `buildTree_MUTATE` now adds to the two different children fields based on the element path representing inner children over property children. - `getReorderedIndexInPaths` further reworked to handle shifting by the siblings. - Fixed some tests that had expressions incorrectly ordered.
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.
Problem:
buildTree
is another function on our hot path for any interaction and can often cost around 2ms of frame time.Fix:
By combining the logic from
buildTreeRecursive_MUTATE
andgetChildrenPaths
, we are able to turn the logic for adding an item to the tree into a function which is executed for the two cases where paths are added. Then it's possible to reshape the recursive call into a loop which avoids some unnecessary array construction. Along with this some tweaks were made to avoid some repetition in the logic which checks the types of the elements as they were working from theElementInstanceMetadata
each time for 5 different cases.To help with ordering and to avoid having to do a lot of re-ordering the
children
field ofElementPathTree
is now split into two distinct fields. As the inner children (from within the component) should be listed ahead of the props children (from within the JSX element in the code).Results:
Benchmarks before:
Benchmarks after:
The above translates to
buildTree
taking about 0.5ms to run consistently.Commit Details:
buildTree_MUTATE
to build the tree from the root downwards, combining it with some of the logic taken fromgetChildrenPaths
.isDescendantOf
replacing the previous implementation.getReorderedPaths
now avoids a lot of repeated logic for checking the element type.ElementPathTree.children
into two separate fieldsto make for easier ordering.
getElementPathTreeChildren
andforEachElementPathTreeChild
utility functions.buildTree_MUTATE
now adds to the two different children fields basedon the element path representing inner children over property children.
getReorderedIndexInPaths
further reworked to handle shifting by the siblings.Manual Tests:
I hereby swear that:
Fixes #6324