I am building a chat app and since React-Native version 0.63, I am having horrible performance when there are long texts involved on an inverted Flatlist, on Android.
Here is a snack repro showcasing the issue (visible only when trying on a physical Android phone).
I reported a bug for it. It should be pretty flagrant for anyone who is building a chat app with an inverted Flatlist, but somehow I don't see this issue being talked about anywhere.
This made me think that maybe others have solved it somehow? If yes, how can I solve it too? It is making my app barely usable right now.
Actually, the
Flatlistcomponent has been written in a better way to have better performance than other list components likeScrollView. But you should consider there are few principles for a very long list like chat:Unique Key: For having unique keys to cache and re-ordering in the best way it is YOU to pass the unique key because
ReactJSjust useitem.keyand if it does not exist theReactJSuseindexand it is the root of the performance issue, SO, you should use a prop that name iskeyExtractorand make a good function to produce unique keys.Skipping The Measurement of Dynamic Content: To avoid the re-calculating items measurements in every re-rendering you could use a prop that name is
getItemLayoutand pass thewidth,height,offset,indexand etc. addinggetItemLayoutcould help you to have a huge performance boost for a long lists with several items.Determine Initial Items' Number: You can determine a number of items to load and avoid showing the seen items, this could be a little tricky but I guess using
initialNumToRendercould help you for initilal loading, after initial you can trim the seen items that they are not in view screen.Remove Clipped Items: For this you can use the prop name that name is
removeClippedSubviewsbut care about it. maybe it has bug in some situations.By my experinces, these ways can improve performance of the long lists. I hope these help you, and maybe there are some other tricks to have better performance.