Skip to content
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

[Android] Extreme lag after upgrade to 0.39.2 and 0.40.0 #11809

Closed
ramilushev opened this issue Jan 10, 2017 · 107 comments
Closed

[Android] Extreme lag after upgrade to 0.39.2 and 0.40.0 #11809

ramilushev opened this issue Jan 10, 2017 · 107 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@ramilushev
Copy link

ramilushev commented Jan 10, 2017

Description

Updating from 0.36.0 to 0.39.2 and 0.40.0 renders the app unusable after minimal interaction. The javascript thread slowly grinds to a halt until it becomes unresponsive. Native UI, such as scrolling or native animations is unaffected. Problem persists with 0.41.0-rc.0

It works perfectly well with 0.38.0

Reproduction

I managed to reproduce this in a freshly installed app with an infinite scroll list containing rows with images. With 0.40.0, the JS driven animation begins to lag after only ~150 items. WIth 0.38.0, animation stays smooth as long as there is no rendering.

See attached videos below:
0.38.0
0.40.0

Test app can be found here

A relative StackOverflow question.

Solution

I suspect the new C-based CSS implementation, as that is the only major change from 0.38 to 0.39. Another reason could be a problem with removeClippedSubviews.

Additional Information

  • React Native version: 0.39.2 / 0.40.0
  • Platform: Android
  • Operating System: MacOS
@sahrens
Copy link
Contributor

sahrens commented Jan 24, 2017

Were you able to confirm that the slowdown is because of more onLayout callbacks happening without actual changes to layout?

@ramilushev
Copy link
Author

@sahrens Yes, I built RN from source from the commit before and all was good ...

@gchiocchio
Copy link

I can confirm this problem in my application, i have updated from 0.36 to 0.40 and UI becomes unusable after render 100 items in a simple listview where the rows are only text and image.
Today I have tested 0.41.0-rc.0 and master but problem is still present.

@10111282
Copy link

I have tested today 0.41.0-rc.1 - still the same.

@nihgwu
Copy link
Contributor

nihgwu commented Jan 31, 2017

I'm facing the same issue, any progress or workaround?

@10111282
Copy link

10111282 commented Jan 31, 2017 via email

@gchiocchio
Copy link

gchiocchio commented Jan 31, 2017

two screenshots of android profiler when I scroll listview:

ygnodecalculatelayout

nativerunnable

@ksegla
Copy link

ksegla commented Feb 11, 2017

I want to add my voice to this chorus. I upgraded from 0.34.1 to 0.40. I was pleasantly surprised by some of the improvements (Dailymotion working well within the Webview, some keyboard problems fixed, screen rotation with better behavior) but then I realised the performance drop. I was close to releasing my app but the problem is so bad I have to wait. Still waiting. Coded as a stop-gap a simple page trick with only 50 elements per page to ensure smooth scrolling and touch responses. And this is is on a Samsung S6. Performance is significantly worse on lower-end/older devices.
This is an extremely serious, almost fatal issue for many projects. I hope it gets fixed very soon.

@matclayton
Copy link

We're seeing the exact same issue here as well, iOS works fine, Android has become very laggy post update.

@K-Leon
Copy link
Contributor

K-Leon commented Feb 17, 2017

Same here
@sahrens Any Idea who is the right person to approach with this issue?

@hubciorz
Copy link

Same here. We had to downgrade to 0.38.

@quietbits
Copy link

And same here. Hopefully this can be addressed soon.

@hubciorz
Copy link

hubciorz commented Feb 17, 2017

@K-Leon I think that @astreet is the author of the commit (d63ba47) introducing the new CSS engine.

@astreet
Copy link
Contributor

astreet commented Feb 20, 2017

This wouldn't be related to that commit -- it's more likely related to #11222 (is anyone able to try reverting that locally and see if the problems go away?)

I'll post internally and try to get someone on it.

@Kerumen
Copy link
Contributor

Kerumen commented Feb 20, 2017

The commit of #11222 was cherry-picked into 0.38 and 0.39. People are reporting the bug doesn't happen on 0.38. So maybe this PR is not the root cause?

@nihgwu
Copy link
Contributor

nihgwu commented Feb 20, 2017

0.38.0 is different from 0.38.1
I haven't test the reverting thing, but I have to say there are a lot of layout issues on Android when I'm trying to implement a HTML render, then I switched to Nodes which is still experimental and all the LAYOUT DON'T UPDATE issues on Android are gone.
But when I upgrade my app to the latest version of RN, I scroll a list to load more data, the following interactions become so buggy that there is nearly no response on touch, and I have to wait for several seconds

@sdcooke
Copy link

sdcooke commented Feb 20, 2017

Reverting that commit makes quite a large difference to us - I'm not 100% certain that performance is back to what it was before 0.39 - we'll continue testing.

@ming436534
Copy link

which commit should I revert to temporarily fix the problem?

@Kerumen
Copy link
Contributor

Kerumen commented Feb 22, 2017

It depends of your RN version as it was cherry-picked in the previous releases:
>=0.40: fb23000
0.39: 4cd4b4b
0.38 9a13def

For 0.38, a simple way to revert it is to switch from 0.38.1 to 0.38 and see if the problem goes away. I don't have a way to reproduce the bug so I can't test it.

But I guess the final solution to this is not to simply revert this commit because it fixes a bug for me and for other people. Basically, we have to get rid of the performance problem without breaking what it solved.

@astreet
Copy link
Contributor

astreet commented Feb 22, 2017

I have a fix in review internally that I'll hopefully get in today. I'll make sure it gets cherry-picked into the next release.

@hubciorz
Copy link

@astreet
Cool! Maybe It is worth to cherry-pick the fix into some older releases, too? Still many apps use 0.39 or 0.38 because of breaking changes in 0.40.

@astreet
Copy link
Contributor

astreet commented Feb 22, 2017

I'm not sure on the feasibility of that, @mkonicek?

facebook-github-bot pushed a commit that referenced this issue Feb 22, 2017
Summary:
Developers are complaining about horrible lag (#11809) caused by PR #11222.

The issue was that hasNewLayout in yoga is actually a dirty bit and indicates that either you OR one of your children has a new layout. We still need to manually check whether the component's layout actually is different from before.

Reviewed By: sahrens

Differential Revision: D4597545

fbshipit-source-id: 27d4605afd00badfdcdacae740ee2e477adee929
@astreet
Copy link
Contributor

astreet commented Feb 22, 2017

Fix is in: 15429e3

Let's make sure it doesn't break anything internally and then we can see about getting it cherry-picked.

@Kerumen
Copy link
Contributor

Kerumen commented Feb 22, 2017

Just tested the fix on my test repo with the bug and it didn't break!
I hope the performance problem is solved for the others and both world will be happy 👍

@Deividy
Copy link

Deividy commented Apr 3, 2017

I tested in 0.44.0-rc.0 and its fixed, thanks! :)

@arsen
Copy link

arsen commented Apr 4, 2017

Hey @grabbou
Just wondering if you had time to cherry-pick it into 0.43.1 ?

@AndrewJack
Copy link
Contributor

@grabbou I noticed 0.43.1 didn't include the yoga fixes, is it possible to cherry pick them or do they depend other commits?

The matching commits in React native are:
facebook/yoga@5884ab7 = 759b8cc
facebook/yoga@5112564 = f1371ec

@grabbou
Copy link
Contributor

grabbou commented Apr 5, 2017 via email

@grabbou
Copy link
Contributor

grabbou commented Apr 6, 2017

0.43.2 is now on Circle and should be on npm in like two hours. If anyone wants this to be cherry-picked into old release, please find the ticket [XXX] commits to cherry-pick and leave a note there.

@grabbou
Copy link
Contributor

grabbou commented Apr 6, 2017

Having said so, can this issue be closed now?

@ramilushev
Copy link
Author

I have tested this and can confirm it is fixed. A big thanks to everyone involved!!! You can close this.

@grabbou grabbou closed this as completed Apr 6, 2017
@andreialecu
Copy link

andreialecu commented Apr 11, 2017

Are you sure this is fixed? I have just finished converting a screen from using ListView to SectionList and it resulted into it being completely unusable on my physical Android 5.0.1 device.

I'm on react-native v0.43.3.

It initializes slowly, taking at least 5 seconds for the initial render, then in the perf monitor the JS thread says -2.1 fps (yes, with a minus).

During this time the app is completely locked up, except for scrolling the list, which seems to work.

The -2.1 fps situation clears itself after 20+ seconds and returns to 60 fps

One interesting thing is that if I enable Remote JS Debugging the app never goes below 60 fps and everything is super fast. Also GenyMotion is super fast as well, just the device has issues (but not when JS is running via remote JS).

Any clues?

@sahrens
Copy link
Contributor

sahrens commented Apr 11, 2017

@andreialecu this issue affected ListView and SectionList similarly I believe, so if you weren't seeing any issues on ListView then my guess is you accidentally introduced some weird perf regression with your transition to SectionList. The fact that the debugger makes a difference also implies a different issue.

If you can't sort out the problem, can you provide a repro case/sample code?

@andreialecu
Copy link

andreialecu commented Apr 11, 2017

It seems like switching JS Dev mode to off helped the problem somewhat, as did removing a few console.log statements I had and disabling redux-logger.

Now it renders almost instantly (or at least without any perceived lag), but the JS thread still stalls bouncing between -2.1 fps, 2.1 fps for close to 10 seconds until it recovers.

All my section headers and list items are PureComponents.

However, if I trim down the renderItem to a simple <Text>Hello World</Text>, it seems to take around 1 second to recover.

The original list item component itself is not super complicated, but has several nested <View>s. I did notice that the more I strip it down, the better performance gets.

This didn't seem to be as much of a problem with ListView.

And if I run it with Remote JS Debugging enabled, it is instant, not exhibiting the problem even with the original renderItem, it never drops below 55fps - not even for a milisecond.

@andreialecu
Copy link

Alright, I kept the code for the ListView and it is identical to the SectionList implementation, but it runs much faster and never drops a frame.

However, now that I got rid of the console.log statements and redux-logger, I see that the issue I was experiencing wasn't this one. I confused the slowness from https://github.com/evgenyrodionov/redux-logger/issues/32 with an issue in react-native rendering.

It still seems like SectionList and/or FlatList have problems, but probably unrelated to this particular issue.

@maxx-coffee
Copy link

I'm still having the weird issue that @andreialecu discussed earlier using 0.43.3. On a physical device our app seems to run incredibly slow becoming unresponsive unless I have remote debugging turned on.

Without remote debugging I will drop to -2.0 fps for 10-20 seconds and then will come back up. During this time the app is not responsive. When I turn on remote debugging I average 50-60 fps.

I do not have any console.logs or redux logger turned on. I have also created a new react-native project and moved my files over with the same issues. At first I thought it could be a redux / data store issue problem. The only problem i see with that is iOS would be affected also.

Any help / ideas would be appreciated.
react-native 0.43.3
react 16.0.0-alpha.6
react-navigation 1.0.0-beta.7
redux 3.5.2

@astreet
Copy link
Contributor

astreet commented Apr 19, 2017

@joshualcoffee Can you take and post a systrace (see #11809 (comment))?

@maxx-coffee
Copy link

@astreet Sure thing. I have created a few videos of a scaled down app vs a larger app.
https://www.dropbox.com/s/ay4mtejsxcmc8xx/2017_04_20_07_05_54.mp4?dl=0
This shows a scaled down app without using debug mode. You can see the frames drops to -2.1 and locking the device for a very short period.

https://www.dropbox.com/s/bh2dkjd8svh00uf/2017_04_20_07_08_23.mp4?dl=0
This shows the scaled down app using debug mode. You can see frames only drop for brief periods to draw / redraw elements. Also page transition are smooth.

https://www.dropbox.com/s/9qu0o93naqfsjmk/2017_04_20_07_14_57.mp4?dl=0
Production app with async calls and more elements to render. This shows both debug mode and non debug mode. You can see the device stays locked up for a time period without debug mode turned on.

Systrace:
https://www.dropbox.com/s/ztwulxavy7915hm/trace.html?dl=0
Nothing stands out to me other than my mqt_js thread does not seem to look like the one you pictured.

@andreialecu
Copy link

andreialecu commented Apr 20, 2017

@joshualcoffee are you using the new FlatList? In my app, as previously mentioned, ListView performs better, however once I scroll down so that new elements are being rendered, I still notice slowdowns that otherwise do not occur when Remote JS Debugging is on.

In general, the entire app seems slightly faster with Remote JS Debugging than without, so I'm not sure why that would happen. I'm on a low powered Android device, but you would think that marshalling to the PC back and forth would negate any performance differences the PC would have compared to the device.

There is also a related react-navigation issue here: react-navigation/react-navigation#706 which I also believe to be react-native related.

@sahrens
Copy link
Contributor

sahrens commented Apr 20, 2017

It's not surprising at all that that things would be faster with remote debugging compared to running on a slow Android device. The marshaling overhead is actually quite small compared to the computation.

@maxx-coffee
Copy link

Ahhh well that's good to know. I think the issue is comparing it to developing on iOS. Typically you will get slower performance when you have remote debugging on during iOS simulation. If this is typical than disregard my comments.

FlatList still seems to be a huge issue for android. Following up what @andreialecu, I had to switch back to ListView as the performance for FlatList was horrible. Im pretty sure I can get around most of the performance issues by fine tuning my connected components. I'm noticing re-renders when there should not be any.

@jemise111
Copy link
Contributor

Hey guys I'm noticing the exact thing @joshualcoffee is after upgrading to 0.43.4. Unusable slow performance but only on an iOS physical device in debug mode, yet turning on remote debugging actually solves the issue.

Only using <ListView />s

Did the fix mentioned above land in 0.43.4 or 0.44.0 or not at all yet? Thanks for the help!

react-native 0.43.4
react 16.0.0-alpha.6

yinhangfeng pushed a commit to yinhangfeng/react-native that referenced this issue May 11, 2017
Summary:
Developers are complaining about horrible lag (facebook#11809) caused by PR facebook#11222.

The issue was that hasNewLayout in yoga is actually a dirty bit and indicates that either you OR one of your children has a new layout. We still need to manually check whether the component's layout actually is different from before.

Reviewed By: sahrens

Differential Revision: D4597545

fbshipit-source-id: 27d4605afd00badfdcdacae740ee2e477adee929
@eseQ
Copy link

eseQ commented Jun 29, 2017

Hello. I`ve same issue.
On android JS thread says -2.1 fps.
Downgrade react-native to 0.38.1 help me (but i want latest rn =))

@merryejik
Copy link

Same after upgrading from 0.42 to 0.48.3

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests