Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Android App consumes 30mA per hour even though app is in background

Performed current drain test on sample (Welcome to React Native) app when the app was in background for an hour and the results are as follows:

Sample application with RN version 34 : 31.54mA Sample application with RN version 22 : 24.60mA 

Where as the sample native android app only consumes about 10mA in the same scenario.

Tools Used :

Power monitor (H/w) Power tool (S/w) 

1) Can anybody confirm the above test and explain the reason behind high current drain ?

2) Is it normal for react native apps to have higher current drain values as compared to the native android app?

React Native version: RN 0.22 and RN 0.34 Platform : Android 

enter image description here

like image 848
Ramesh Vishnoi Avatar asked Oct 19 '16 07:10

Ramesh Vishnoi


People also ask

Can React Native apps run in the background?

In React Native, performing a task in the background might seem daunting at first. It is not as simple as writing a function in JavaScript, where the function is executed even after the activity is killed. Instead, React Native uses Headless JS to execute JavaScript code in the background.

Why is React Native so slow on Android?

Slow app launch is another issue of React Native apps. If your app opens too slowly, you probably have too many dependencies in your app and you're using slow components. Try to use fast, high-performance components and decrease the number of dependencies in your app. For example, the Object.

Is React Native faster than Android?

Even without using hot reloading, app build time is significantly faster using React Native than on native iOS and Android, and live reloading mechanism can be used to automatically reload the app every time the code is changed, without having to build it manually every single time.


1 Answers

While I do not know the internals, I believe the following statement is a good hypothesis;

Even when you have installed the application in release mode (in other words, there is no npm server and the app uses local .jsbundle) React Native has to keep two things working;

  1. A native thread to respond to whatever our JS code required (draw this, get geolocation etc.)
  2. A Javascript VM to interpret our code. (.jsbundle file included with the APK)

I believe, due to this added load, a react native app should consume more power, assuming everything else is equal.

like image 183
H. Tugkan Kibar Avatar answered Oct 02 '22 23:10

H. Tugkan Kibar