Repository navigation
Poor performance in Android production build #17033
Description
Activity
Here's some tips I picked up from building a few apps.
- Try to use React Native's FlatList/SectionList/VirtualizedList where you can and not
array.map()as it allows for asynchronous rendering of components in your viewport which is important for mobile devices. - With the nature of React, any component that has updates to it's state/props will re-render all of it's child components, and likely the children of those components as well. It's up to you to make sure that your components should update or not by using
shouldComponentUpdateor changing the components to a PureComponent. There's often times where you don't even know that components are re-rendering when they shouldn't be. Start by checking the app root component and going down from there. - React Navigation will typically have any screen you have in your navigation state rendered. State-heavy screens may suffer in performance especially when there's background state updates. It's also easy to add more routes to your navigation state and more difficult to take them off.
- Make sure that the screen you're trying to navigate to isn't heavy on it's initial render. Your components should preferably be light on the first render and accumulate with data later from interaction and server responses. react-navigation will only transition to the screen once it's typically fully rendered. One thing that could help is configuring
initialNumToRenderon your FlatList/SectionList component. Otherwise this may take seconds to render new screens using react-navigation. - The
renderItemfunction should render stateless list item components. If it needs state context (e.g. whether the list item is expanded or selected), it should be using the parent's state as seen in the documentation. - Unusual things may start happening if you render more than one FlatList/SectionList/VirtualizedList in one component (e.g. rendering only the current render batch and no more).
- Avoid wrapping your FlatList inside a ScrollView, as it will render all child components. FlatLists implement on top of ScrollView's so you can use most ScrollView props on FlatLists.
- Develop Android-first. iOS performance is guaranteed and you will notice performance issues sooner before having to rebuild much of your code base. React-Native was built first with iOS-only support.
- Using remote debugging will execute JavaScript on the host computer and not on the phone, and instead use the RN bridge to send native calls to the phone. This will likely be very slow in some situations and very fast in others. Try building the app with the release variant --
react-native run android --variant=releaseso you can get a more accurate feel of the app's performance. - Remove any console.log() statements from your app when releasing it to production with babel-plugin-transform-remove-console.
- Generally as a guideline, the less JavaScript and more native code, the better performance you'll get. React Native allows us to build user interfaces with great productivity and a shared code base but there may be times that you'll need to go native on both platforms to get better performance.
react-navigation is a not very performant library especially for Android. It solely uses React Native's library as a basis for all it's navigation logic which means any additional screens/views are all loaded on to the one activity/viewcontroller which gives 'native-like' navigation but not true navigation. If you went to inspect the app on iOS while the app was running you'd see that the screens in your navigation state are essentially rendered and layered on top of each other. react-native-navigation (v1) is a suitable alternative if you'd rather want to use the native navigation controllers.
Reacted by busmobileapp, minhphung210, Jacky Li, JohnZ, Jan Ziemba, Himanshu Kushwah and Tyler NickersonReacted by Noitidart, Daniel Steigerwald, Kristjan Vool, Amr Abd El Wahab El Desouky, Trust, Tracey, Gerardo Pacheco, fxwan, Aseem Gautam, HZSamir and 7 more- Try to use React Native's FlatList/SectionList/VirtualizedList where you can and not
FlatList 'pull-up load more' Sometimes do not trigger, sometimes trigger, do not trigger, you need to roll back a roll。My onEndReachedThreshold is already set to 0.1。Is there any way to fix this problem?
Reacted by TuNAFlatList and SectionList is bad performance. Try this,please. may be it is a surprise for you
https://github.com/bolan9999/react-native-largelist
+1
same issue heresame issue, it is not about flatlist, it is the whole app being crazily slow. even takes more than 5 seconds for simple navigation. and the app works perfect on ios
Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?
I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.
- addedRan CommandsOne of our bots successfully processed a command.One of our bots successfully processed a command.StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
on Feb 24, 2018 - This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a temporary error. The following address(es) deferred: mkdirenv@gmail.com Domain salmanwaheed.info has exceeded the max emails per hour (185/150 (123%)) allowed. Message will be reattempted later------- This is a copy of the message, including all the headers. ------ Received: from github-smtp2-ext6.iad.github.net ([192.30.252.197]:40637 helo=github-smtp2b-ext-cp1-prd.iad.github.net) by box1177.bluehost.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from <noreply@github.com>) id 1epQW5-003Jhv-2c for hello@salmanwaheed.info; Fri, 23 Feb 2018 20:28:53 -0700 Date: Fri, 23 Feb 2018 19:25:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=github.com; s=pf2014; t=1519442906; bh=LzFYFH+3k7hLm7JXOwWq4Odf3GwjRCGc0ncHmsvFSVE=; h=From:Reply-To:To:Cc:In-Reply-To:References:Subject:List-ID: List-Archive:List-Post:List-Unsubscribe:From; b=dGunmr8C10bahbM24Qtaxvx8x+GA5o7LehV8yGJeSWdtPLEObtVuTUlFTYcYE2Sha 96vBXDmzpcIgvCy8mcab9aRtLPAsxrB90Vb95NvculLBqTLh0uPHlI6DFe8+vubHJW BkfpAIBETCBDQe7jqQfN8hp/mmUDCsipfqaIQNNA= From: React Native Bot <notifications@github.com> Reply-To: facebook/react-native <reply@reply.github.com> To: facebook/react-native <react-native@noreply.github.com> Cc: Subscribed <subscribed@noreply.github.com> Message-ID: <facebook/react-native/issues/17033/368195187@github.com> In-Reply-To: <facebook/react-native/issues/17033@github.com> References: <facebook/react-native/issues/17033@github.com> Subject: Re: [facebook/react-native] Poor performance in Android production build (#17033) Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="--==_mimepart_5a90db1e167ec_56012ad304abaed01866a3"; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: list X-GitHub-Sender: react-native-bot X-GitHub-Recipient: salmanwaheed X-GitHub-Reason: subscribed List-ID: facebook/react-native <react-native.facebook.github.com> List-Archive: https://github.com/facebook/react-native List-Post: <mailto:reply@reply.github.com> List-Unsubscribe: <mailto:unsub+00ef1b383c63442541564aa66b1d1cab57d57306bed980c392cf0000000116a89d1e92a169ce1095a405@reply.github.com>, <https://github.com/notifications/unsubscribe/AO8bOCTJp8-Bv6okaXMRt9uagMlkLX-5ks5tX4EegaJpZM4QxFOm> X-Auto-Response-Suppress: All X-GitHub-Recipient-Address: hello@salmanwaheed.info X-Spam-Status: No, score=-1.0 X-Spam-Score: -9 X-Spam-Bar: - X-Ham-Report: Spam detection software, running on the system "box1177.bluehost.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see root\@localhost for details. Content preview: Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version? [...] Content analysis details: (-1.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: github.io] -0.5 SPF_PASS SPF: sender matches SPF record 0.0 HTML_IMAGE_ONLY_32 BODY: HTML: images with 2800-3200 bytes of words 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.4 AWL AWL: Adjusted score from AWL reputation of From: address X-Spam-Flag: NO----==_mimepart_5a90db1e167ec_56012ad304abaed01866a3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks for posting this! It looks like you may not be using the latest ve= rsion of React Native, v0.53.0, released on January 2018. Can you make su= re this issue can still be reproduced in the latest version? = I am going to close this, but please feel free to open a new issue if you= are able to confirm that this is still a problem in v0.53.0 or newer. <sub>[How to Contribute](https://facebook.github.io/react-native/docs/con= tributing.html#bugs) =E2=80=A2 [What to Expect from Maintainers](https://= facebook.github.io/react-native/docs/maintainers.html#handling-issues)</s= ub>-- = You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: #17033 (comment) 187=----==_mimepart_5a90db1e167ec_56012ad304abaed01866a3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p>Thanks for posting this! It looks like you may not be using the latest= version of React Native, v0.53.0, released on January 2018. Can you make= sure this issue can still be reproduced in the latest version?</p> <p>I am going to close this, but please feel free to open a new issue if = you are able to confirm that this is still a problem in v0.53.0 or newer.= </p> <p><sub><a href=3D"https://facebook.github.io/react-native/docs/contribut= ing.html#bugs" rel=3D"nofollow">How to Contribute</a> =E2=80=A2 <a href=3D= "https://facebook.github.io/react-native/docs/maintainers.html#handling-i= ssues" rel=3D"nofollow">What to Expect from Maintainers</a></sub></p> <p style=3D"font-size:small;-webkit-text-size-adjust:none;color:#666;">&m= dash;<br />You are receiving this because you are subscribed to this thre= ad.<br />Reply to this email directly, <a href=3D"https://github.com/face= book/react-native/issues/17033#issuecomment-368195187">view it on GitHub<= /a>, or <a href=3D"https://github.com/notifications/unsubscribe-auth/AO8b= ONhVpffFTi4xE_NSCyCnOFt7BV67ks5tX4EegaJpZM4QxFOm">mute the thread</a>.<im= g alt=3D"" height=3D"1" src=3D"https://github.com/notifications/beacon/AO= 8bOCuJ0MeP9BdQfEt0urLDMktR4iOBks5tX4EegaJpZM4QxFOm.gif" width=3D"1" /></p=<div itemscope itemtype=3D"http://schema.org/EmailMessage"> <div itemprop=3D"action" itemscope itemtype=3D"http://schema.org/ViewActi= on"> <link itemprop=3D"url" href=3D"https://github.com/facebook/react-native= /issues/17033#issuecomment-368195187"></link> <meta itemprop=3D"name" content=3D"View Issue"></meta> </div> <meta itemprop=3D"description" content=3D"View this Issue on GitHub"></me= ta> </div> <script type=3D"application/json" data-scope=3D"inboxmarkup">{"api_versio= n":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name"= :"GitHub"},"entity":{"external_key":"github/facebook/react-native","title= ":"facebook/react-native","subtitle":"GitHub repository","main_image_url"= :"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d8= 8-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubuse= rcontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.= png","action":{"name":"Open in GitHub","url":"https://github.com/facebook= /react-native"}},"updates":{"snippets":[{"icon":"PERSON","message":"@reac= t-native-bot in #17033: Thanks for posting this! It looks like you may no= t be using the latest version of React Native, v0.53.0, released on Janua= ry 2018. Can you make sure this issue can still be reproduced in the late= st version? \n\nI am going to close this, but please feel free to open a = new issue if you are able to confirm that this is still a problem in v0.5= 3.0 or newer.\n\n\u003csub\u003e[How to Contribute](https://facebook.gith= ub.io/react-native/docs/contributing.html#bugs) =E2=80=A2 [What to Expect= from Maintainers](https://facebook.github.io/react-native/docs/maintaine= rs.html#handling-issues)\u003c/sub\u003e\n\n"}],"action":{"name":"View Is= sue","url":"#17033 (comment) mment-368195187"}}}</script>=…----==_mimepart_5a90db1e167ec_56012ad304abaed01866a3--
@BG687 did you find a solution for this at all?
Reacted by Jan Ziemba and rterysen- locked and limited conversation to collaborators
on May 15, 2018
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment:
npm: 4.2.0
Watchman: 4.6.0
Android Studio: 2.3.3
Packages: (wanted => installed)
react: 15.6.1 => 15.6.1
react-native 0.50.3 => 0.50.3
react-redux: 5.0.6 => 5.0.6
redux: 3.7.2 => 3.7.2,
Steps to Reproduce
So, my react-native app's performance is good in production mode in iOS -- native-feeling transitions, smooth animations, etc. However, on Android, we have serious performance issues -- multi-second delays for simple transitions, choppy animations, etc. The app is basically great in iOS and not usable in Android.
We have tried to follow the react native performance docs. We have taken out all the console logs, swapped ListViews with FlatViews and SectionViews, made animations useNativeDriver, etc.
We have also followed the guides for building in production mode -- turn debuggable to false in the app's build.gradle, set the build-variant to release, generate a signed APK with a keystore .jks file, etc. etc.
We have tested Android performance on the emulator and on two devices -- on a new Galaxy S8 and a 2013 Nexus 7 tablet. The performance is poor on both devices. We have deleted the cache, uninstalled the app, cleaned the build folder, and rebuilt many times.
Any ideas on how to fix this? It is odd that there is such a big performance hit in Android, and we are thinking there could be something easily remedied that we are missing.
(Write your steps here:)
Expected Behavior
We thought performance in Android would be similar to the performance of production builds in iOS
Actual Behavior
Performance is very slow, as described two sections above.
Reproducible Demo
Since this is an issue related to building in Android Studio, a demo may not be very useful here. Just note that ALL transitions are very slow in Android but normal / fast in iOS. We have tried using different navigation libraries, including react-navigation, but that has not helped with this issue.