19

I'm currently down the path of trying to figure out how to decrease Android startup time. It hasn't been an issue with iOS but for Android, I'm seeing anywhere from 6-10 seconds. The goal is to be around 3-4 seconds.

Here's a summary of the research I've come across

  • createReactContext: where the react bridge gets initialized and starts loading all the native modules
  • getMethodDescriptors: using reflection it compiles (run-time) a list of all exposed methods using ReactMethod

Solutions exist but not perfect:

  1. LazyReactPackage (Experimental) https://github.com/facebook/react-native/commit/797ca6c219b2a44f88f10c61d91e8cc21e2f306e
  2. Removing reflection for all exposed ReactMethods https://github.com/facebook/react-native/pull/10084

My problem with these solutions is around using annotation processing to generate classes (compile time). I'm trying to figure out how to get these solutions running with no luck.

Also, other suggestions around decreasing startup time for Android would be helpful.

Thanks!

howdy_miguel
  • 473
  • 5
  • 17
  • 6
    did you get any solution? – Alauddin Ahmed Apr 21 '18 at 16:21
  • If anyone is interested here's the overall changes made to increase startup time on Android: https://github.com/mattermost/mattermost-mobile/pull/1598 Required a lot of measuring and understanding of the costs of startup – howdy_miguel May 30 '19 at 13:09

3 Answers3

2

For this Facebook has released their new build mechanism Hermes which will increase the speed of your startup time. But you need react native 0.60> to use this engine. https://facebook.github.io/react-native/blog/2019/07/17/hermes

0

Based on information above it's hard to answer what is the bottleneck on Android devices, since the question lack a lot of information, such as devices specifications, on which you made tests, react-native version, etc.

The question was asked a long time ago, and I think at that time the main bottleneck was in the usage of old JSC. Since RN started to use own JSC (not Android default) only from 0.59 version. As other people pointed, starting from RN 0.60 they also added an ability to use Hermes engine (which is available from RN 0.64 on iOS too). All these optimizations were made in order to improve performance on Android devices.

I think now, using RN 0.60 with new JSC or with Hermes it will not be a problem. And the time of startup will be roughly equal (or maybe even faster) than on iOS (assuming that you will make your tests on similar device).

However, if you still think, that you should optimize your startup time you can look at ram bundles. This mechanism allows you to load only part of JS bundle, that you need at a startup (in a lot of application are a lot of places, which user may not even see, and this feature allow you load such parts, only when they are required). So you can simplify your entry point and load only small piece of your bundle.

You can look at react-native-bundle-splitter. This library well integrated with almost all popular navigation libraries and allows you to postpone a loading of specific routes. For example, if you have a login screen, you can load at start up only this screen, and all others load in background or start the loading of them, only when user can see them. And the startup time of your complex application will be almost equally as for "Hello world" application.

Kirill Zyusko
  • 119
  • 1
  • 1
  • 11
-1

Use expo optimize in your project directory. You should also make sure you have not added any extra packages as the js packages will be downloaded on the first startup.