-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make sure style does not regenerate between renders if it is the same. #3126
Conversation
src/createAnimatedComponent.tsx
Outdated
if (!changed) { | ||
const lastKeys = Object.keys(this._lastSentStyle); | ||
const inputKeys = Object.keys(inputStyle); | ||
if (lastKeys.every((k) => inputKeys.includes(k))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is safe enough to test only for the lengths. The case that bothers me is:
inputStyle = {
var1: 1,
var2: 2,
var3: undefined,
}
lastStyle = {
var1: 1,
var2: 2,
var4: 5,
}
@piaskowyk Would you consider this PR for the next release? I think the changes will be quite helpful to improve app performance. |
@AlexanderEggers I will try, but I see here a potential issue with the race condition of the update on the UI thread (mappers). I need to prepare some tests for this PR. |
src/createAnimatedComponent.tsx
Outdated
if (!changed) { | ||
const lastKeys = Object.keys(this._lastSentStyle); | ||
const inputKeys = Object.keys(inputStyle); | ||
if (lastKeys.every((k) => inputKeys.includes(k))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would at least make it a for of loop with key in inputStyle
so we won't have a loop (includes
) for every loop iteration (every
) for no reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some code to avoid the double loop.
We have to iterate through the lastStyle, since we already know all relevant information from the input style is present in lastStyle. What we have to make sure is that no extra information is being sent through lastStyle (no extra key in lastStyle that is not present on inputStyle).
I could populate the Set in the previous for, but not sure what is faster (initializing the set directly with an array, or adding one by one the elements).
Just stumbled upon this issue myself. This is generating significant re-renders on my app since I started using Layout Animations in various core components. I am happy to have found this PR so I can at least patch locally :) |
@terrysahaidak Any news here? |
@piaskowyk Any news regarding this PR? |
Hey, I see problem that you don't handle nested properties for example |
After the changes on |
Description
This PR deals with one performance issue generated by creating a new style object on every render.
Any re-rendering of the parent component may make this component to re-render, and it will generate a brand new style property. This calls the re-rendering from the whole tree below this. This can be specially troublesome with components like VirtualizedLists (which have right now performance problems of their own facebook/react-native#31327 ).
Changes
Test code and steps to reproduce
Flipper can be used to track the re-renders and the reasons. Any simple three level design should be able to reproduce this error. For example:
If we re-render the Level1, Level3 should not be re-rendered.
Checklist