-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Flatlist performance slow #13649
Comments
I think that you have to create a React.PureComponent for each item that you render in renderItem:
This should make performance much better since items will not update everytime, as suggested here http://facebook.github.io/react-native/releases/0.44/docs/flatlist.html (doc version 0.44). Otherwise you can use http://facebook.github.io/react-native/docs/virtualizedlist.html#shoulditemupdate , but it will be deprecated in 0.44 in favor of React.PureComponent. Before using PureComponent read the following: This is a PureComponent which means that it will not re-render if props remain shallow- equal. Make sure that everything your renderItem function depends on is passed as a prop that is not === after updates, otherwise your UI may not update on changes. This includes the data prop and parent component state. |
@navid94 Thank you so much man, you saved my life! |
@navid94 Thank you so much man! |
Thank you for this! I should read the docs more clearly. |
Implement |
How can i update particular row in flatlist by onPress for above code |
Great stuff. This was huge performance boost for my several large lists connected to a socket. You just saved me from a lot of refactoring. 👍 |
Are functional components even better in this case than pure components? My list items don't need state at all, so I figured that would be the most performant solution? Or are they going to be not as efficient as a pure component for some reason? EDIT: Functional components are not better in cases like this. You want to use pure components or shouldComponentUpdate. |
I wrote a simple app here that shows a few different options for rendering with flat lists and a simple render time log by comparing the componentWillUpdate and componentDidUpdate calls, the main thing to keep in mind is whenever you render a collection of components and use From my understanding the main cause of the performance difference is mainly due to unnecessary function allocation per render cycle - you'll definitely see this if your child components have something like onPress={()=>{}}. In my example I render a list of very simple components in a few different ways, even in this simple example there is a vast difference in render time between the first approach and the others:
@gregblass in this example, the difference between using pure components was almost non-existent, you could try tweaking the above example with a more complex component. |
@gregblass according to this medium post, pure components are faster than stateless functional components, while stateless & stateful components are basically the same. |
I don't get it. |
@ navid94 Thank you so much, you just saved my day |
Description
I'm using FlatList to load some records. Above the FlatList I have a button and when I tap this button with 230 items loaded in the FlatList, the performance gets horrible.
I'm using a Smartphone ASUS Zenfone Go LTE ZB500KL-1A058BR with android 6.0
I've created a video to better illustrate:
http://www.youtube.com/watch?v=EIlDnoewVhc
My code:
Solution
Maybe something is wrong with my display: none / block?
Additional Information
The text was updated successfully, but these errors were encountered: