-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[RNMobile] Add memoization to the columns width mechanism #28743
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
Size Change: 0 B Total Size: 1.36 MB ℹ️ View Unchanged
|
lukewalczak
reviewed
Feb 8, 2021
lukewalczak
approved these changes
Feb 8, 2021
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.
In this PR I added memoization to the inner blocks widths array in the columns block. Unfortunately, the reference to the innerBlocks is different with every change of attribute of a nested block. That means if we have Columns -> Column -> [Image, Paragraph...] and we type one sign in the paragraph, the whole columns block (all columns inside etc) is re-rendered with its children which is unacceptable. It is even worse for more nested structures like Columns -> Column -> Columns -> Columns -> Paragraph because then the root columns block Is re-rendered on each change in paragraph (all blocks inside are re-rendered as well).
To calculate the width of each column we need only its clientId and width from the attributes. Instead of using the innerBlocks directly, I use the map to remove not needed data and use JSON.stringify to check if something has changed (unfortunately it has to be always a new reference).
Thanks to that we do not render columns block on each change of attributes of its nested blocks.
How has this been tested?
Everything should work as before.
Screenshots
I tested it by adding only one sign into the paragraph nested in columns. I tested few "markups"
Columns -> Column -> Paragraph (No more blocks)
Change from 27.29ms to 14.15ms
Columns -> Column -> Columns -> Column -> Columns -> Column -> Paragraph (No more blocks)
Change from 52.31ms to 21.56ms
Columns -> Column -> Columns -> Column -> Paragraph (With a lot of other blocks - Morden Mountain home page template)
Change from 107.78ms to 19.39ms
Types of changes
Performance improvement
Checklist: