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.
Summary
Using FlatList components with 50 items, and the default values for
initialNumToRender
andmaxToRenderPerBatch
, the following happens:So the flat list is rendering the first 10 items 5 times. It is a performance issue when the items are complicated, or the FlatList has many items. Having N items the FlatList will render O(N^2) items over time.
This PR adds a
shouldComponentUpdate()
for theCellRenderer
that always return false to disable redundant renders. It seems it doesn't break anything. For our apps it also reduces about 1 second of CPU usage of calls toReact.createElement
when rendering some components in our app.An alternative to this PR is to add the same shouldComponentUpdate() in our own items. However, that is a problem for functional components and not as efficient as checking for update in FlatList itself.
https://reactnative.dev/docs/optimizing-flatlist-configuration#use-shouldcomponentupdate
If this change breaks something that I am not aware of, we can add some flag/function prop to FlagList, so the logic in
CellRenderer.shouldComponentUpdate()
can be set by the users.Changelog
[JavaScript] [Fixed] - Don't render list items if not changed.
Test Plan
Current tests should pass.