-
Notifications
You must be signed in to change notification settings - Fork 24.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
Long text in inverted Flatlist causes huge performance drop on Android #30034
Comments
Just checked it in production and the performance hit is still there, making the app feel laggy. |
This issue appears as soon as you invert a ScrollView actually, as you can see on this snack: https://snack.expo.io/@divone/c0c1f3 Again, only visible on a physical Android device. |
It seems that the issue only happens on some phones. For me, it happens on a Google Pixel 4 with Android 11. |
I see this issue on Pixel4 XL running Android 11, which was working fine on React Native 0.61.5 with Android 10. I notice that when the keyboard is open it does not seem to lag. |
Hey @divonelnc thanks for the investigation! I noticed the same issue when running your example. |
Facing this issue on a Samsung Galaxy Note10 running Android 11 as well with Expo SDK 39. Didn't happen on Android 10. Discovered that changing the |
Experienced this issue as well. I upgraded my Samsung Galaxy S10 from Android 10 to Android 11 and suddenly experienced a noticable lag on the |
Im experience the same issue on android with a Samsung Galaxy s10 Android 11, and i noticed after updated the same issue. And i even have it if i don't have long text (The text element goes full width with short text) |
@cookiespam's workaround works. for a less intrusive fix, we could "invert" twice ourselves, once in the container and once in every cell return (
<FlatList
// ...
style={{scaleY: -1}}
renderItem={({item}) => {
return (
<View style={{scaleY: -1}}>
{/* cell content */}
</View
);
}}
>
); for ios, could just use the official |
I was just trying to invert the |
@cookiespam then that was a good accident 👍 |
I also encounter this issue with my chat screen. It's really hard to find to root cause.
It's only take 10 items in the list for the performance to be hit really bad. I'm using @cookiespam bandaid + Here is the the content of the patch:
diff --git a/node_modules/react-native/Libraries/Lists/VirtualizedList.js b/node_modules/react-native/Libraries/Lists/VirtualizedList.js
index 9ec105f..a8f1d8c 100644
--- a/node_modules/react-native/Libraries/Lists/VirtualizedList.js
+++ b/node_modules/react-native/Libraries/Lists/VirtualizedList.js
@@ -11,6 +11,7 @@
'use strict';
const Batchinator = require('../Interaction/Batchinator');
+const Platform = require('../Utilities/Platform');
const FillRateHelper = require('./FillRateHelper');
const PropTypes = require('prop-types');
const React = require('react');
@@ -2185,9 +2186,14 @@ function describeNestedLists(childList: {
}
const styles = StyleSheet.create({
- verticallyInverted: {
- transform: [{scaleY: -1}],
- },
+ verticallyInverted:
+ Platform.OS === 'android'
+ ? {
+ scaleY: -1,
+ }
+ : {
+ transform: [{scaleY: -1}]
+ },
horizontallyInverted: {
transform: [{scaleX: -1}],
},
|
Wow wow wow thank you guys this fix is a lifesaver !!! 🙏 I was actually trying to replace my FlatList by a ScrollView to see where the issue was coming from and noticed then that without inverting the FlatList the performance was fine. Now I can keep my FlatList inverted, it works exactly same as before without changing any other props and I'm going from horrible 40-50fps (since updating to Android 11) to butter smooth 90fps 😍 the solution proposed by @vinceplusplus is what I will be using:
Is someone considered making a pull request with @cookiespam and @pqkluan's patch? I could make one in a couple of days when I get some free time but I also don't want to steal your moment of glory haha |
@cookiespam You are legend, worked for me too. |
using the It renders on the top of the screen as you attempt to scroll down and in order to actually scroll you'll need to scroll up then down to "free" the pan responder somehow. |
I think I love you, thank you! |
I'd just wanted to drop in and say thank you as well 🙏🏼💙 I was severely confused when I upgraded to Android 11 (on a Redmi Note 8 Pro) and the performance on the chat screen in my app was suddenly horrible. Scrolling for a couple of seconds resulted in 1000+ dropped frames. It was so laggy and jerky that one got almost dizzy by watching it. Based on your suggestions I've implemented a simple check (with const useAndroidInvertedFix = useMemo(
() => Platform.OS === 'android' && Number(getSystemVersion()) >= 11,
[],
); I'm extremely grateful for this workaround, however the underlying issue should be officially addressed by react-native itself, right? |
@KochMario the best way to get this fix in is by submitting a PR. Unfortunately the team can’t address every issue as most are not a priority. But there is a massive effort right now to evaluate PrS submitted by contributors. |
I have been struggling to understand why my chat was lagging when tested on a Samsung S20 ultra with 12gb of RAM while it works prefectly on my xiaomi 9 with just 3GB of RAM. And the comments in this thread helped me fix the issue. |
resolved my issue on As @nero2009 mention it has issue with Android devices for lag scrolling (not smooth like in iOS). If you are using |
I see but I am not using Expo or Virtualized List. I am using basic flatList from React Native and rotate will fix the issue. Thanks for help! |
|
@Andrija00 are you check using shopify/FlashList for you chat (10k char messages)? |
@hannojg do you have an idea when it will go out?
|
@anatooly We had issues using FlashList in the past for our ChatScreen component so we stick with FlatList |
@hannojg great work!! 💪 😍 |
The fix is part of RN 0.72.4, you can upgrade and test 😊 |
Perhaps this issue should be closed? |
if anyone can confirm that it's fixed I'd be happy to close |
The issue seems fixed for me after updating my app @kelset I don't experience any performance issues anymore on either the new or old architecture, the UI thread's fps is solid now |
EDIT: I had tried to play around with FlashList instead and forgotten to change it back to FlatList. By using FlatList the issue does indeed seem to be fixed, although now the scroll indicator is on the left. The remedy in this PR (38073) did not work for me. I tried deleting caches and such, but to no avail. I am using expo under windows and I followed this cache invalidation list. RN 0.72.6 and this is my code: <FlatList
data={list}
renderItem={({ item }) => <ListItem item={item} />}
inverted
/> So nothing exotic going on. Vertical scroll bar still on the left. |
@daidonpah Are you sure your flatlist doesn't have any custom styles? Because that may cause the wrong position of the scrollbar. If you don't, are you able to reproduce in a clean new app? If so, I think I'd be good to open a new issue 😊 |
@daidonpah Have you solved the issue using FlashList? Edit: I tried using FlashList and the problem seems to be solved. |
Looks like the performance issue is fixed with v0.72.4 with this line using I'm using Expo 48 and it uses const styles = StyleSheet.create({
inverted: {
...Platform.select({
android: {
transform: [{ scale: -1 }],
},
})
}
})
...
return (
<FlatList
// inverted={true} on Android 33+ will cause performance issue
inverted={Platform.OS === 'ios'}
// apply the inverted style on android
style={styles.inverted}
// hide the scroll indicator on android because it shows on the left
showsVerticalScrollIndicator={Platform.OS === 'ios'}
listFooterComponent={
<View style={styles.inverted}>
<Header/>
</View>
}
renderItem={({ item }) => {
return (
<View style={styles.inverted}>
{renderItem(item)}
</View>
)
}}
/>
) |
@foloinfo on earlier versions this workaround works without compromising the scrollbar: |
Summary: Three changes here: 1. We don't need the Android `FlatList` hack anymore. It's [solved in 0.72.4](facebook/react-native#30034 (comment)). This patchfile now only needs to cover our custom iOS image pasting logic. 2. An upstream React Native change caused the order of the lines in `- (void)paste:(id)sender` to flip. I kept the new order. 3. I had to move the changes in `TextInput.js` to `TextInput.flow.js`. I could have left them in `TextInput.js`, but Flow doesn't seem to pay attention to that file, and I figured a simpler patchfile would be better. Test Plan: Flow Reviewers: atul
Summary: Three changes here: 1. We don't need the Android `FlatList` hack anymore. It's [solved in 0.72.4](facebook/react-native#30034 (comment)). This patchfile now only needs to cover our custom iOS image pasting logic. 2. An upstream React Native change caused the order of the lines in `- (void)paste:(id)sender` to flip. I kept the new order. 3. I had to move the changes in `TextInput.js` to `TextInput.flow.js`. I could have left them in `TextInput.js`, but Flow doesn't seem to pay attention to that file, and I figured a simpler patchfile would be better. Test Plan: Flow Reviewers: atul
Summary: Three changes here: 1. We don't need the Android `FlatList` hack anymore. It's [solved in 0.72.4](facebook/react-native#30034 (comment)). This patchfile now only needs to cover our custom iOS image pasting logic. 2. An upstream React Native change caused the order of the lines in `- (void)paste:(id)sender` to flip. I kept the new order. 3. I had to move the changes in `TextInput.js` to `TextInput.flow.js`. I could have left them in `TextInput.js`, but Flow doesn't seem to pay attention to that file, and I figured a simpler patchfile would be better. Test Plan: Flow Reviewers: atul
Summary: Three changes here: 1. We don't need the Android `FlatList` hack anymore. It's [solved in 0.72.4](facebook/react-native#30034 (comment)). This patchfile now only needs to cover our custom iOS image pasting logic. 2. An upstream React Native change caused the order of the lines in `- (void)paste:(id)sender` to flip. I kept the new order. 3. I had to move the changes in `TextInput.js` to `TextInput.flow.js`. I could have left them in `TextInput.js`, but Flow doesn't seem to pay attention to that file, and I figured a simpler patchfile would be better. Test Plan: Flow Reviewers: atul
Summary: Three changes here: 1. We don't need the Android `FlatList` hack anymore. It's [solved in 0.72.4](facebook/react-native#30034 (comment)). This patchfile now only needs to cover our custom iOS image pasting logic. 2. An upstream React Native change caused the order of the lines in `- (void)paste:(id)sender` to flip. I kept the new order. 3. I had to move the changes in `TextInput.js` to `TextInput.flow.js`. I could have left them in `TextInput.js`, but Flow doesn't seem to pay attention to that file, and I figured a simpler patchfile would be better. Test Plan: Flow Reviewers: atul
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Not stale! |
Keep this open amigo |
This issue has been fixed in recent versions of React Native unless you are still experiencing it, in which case it may be more appropriate to open a new issue
|
Description
I recently upgraded to react 0.63.2 thanks to the latest Expo SDK 39. I immediately noticed that my most important FlatLists took a huge performance hit on Android (iOs seem unaffected).
After investigating, I found out that it happens when using
inverted
on a FlatList that contains items with a lot of text (see snack).The same Flatlist, with the same data, is perfectly smooth when not inverted.
I have yet to test it in production, as the latest Expo SDK is causing trouble that stops me from building the app.
React Native version:
react-native: https://github.com/expo/react-native/archive/sdk-39.0.0.tar.gz => 0.63.2
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
Expected Results
The Flatlist should be as smooth when inverted as when normal.
Snack, code example, screenshot, or link to a repository:
https://snack.expo.io/@divone/4c8d68
The text was updated successfully, but these errors were encountered: