Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native for android run very slow when not enable "Debug JS"

I am developing an app using react native, I use some code base for ios and android, the ios version run smoothly.

But the android version run very slowly. the weird thing is:

When I shake the phone, and click "Debug JS" to enable debug in chrome feature, it run faster, anyone have a clue about the reason?

like image 891
LanceHub Avatar asked Nov 06 '15 09:11

LanceHub


3 Answers

Sometimes, one or more than one active console.log() lines cause this issue. console.log lines should be searched and deleted if they exist.

Also in production, babel-plugin-transform-remove-console can be used to clear all console.* methods automatically.

like image 84
efkan Avatar answered Oct 07 '22 21:10

efkan


The reason for different execution speeds of javascript code when running in debug mode and without is that when you are in debug mode, in order to enable the debugging experience React Native executes the code in the Chrome browser on your computer, and the results of the execution are bridged onto the device.

Outside of the debug mode, the code is executed in the JavaScriptCore engine on the device itself.

That said, I cannot explain why the execution is so slow on the device. Are you perhaps running on an low-powered device, or an emulator with limited allocated memory?

like image 41
jevakallio Avatar answered Oct 07 '22 21:10

jevakallio


React Native app does run slower on Android. But the performance is not real during your development. You can build a release version to check the real performance, release version is much faster than dev version.

There are also some bad codes which can make your app slow. Like console.log(), it does slow the app during development. Avoid unnecessary re-render the view, don't use arrow function and .bind in render, etc.

like image 7
Swordsman Avatar answered Oct 07 '22 21:10

Swordsman