hermes: Android release converting js bundle to byte code is very slow

Bug Description

We recently added a bunch of json files containing (thousands of) nested arrays of numerical data to our RN app. Each of these files is around 1.2MB minified. We conditionally access the data from within our app through inline requires like this: const data = require('./path/to/the/file.json');

Running our app in development mode is still working fine as is building a release bundle for iOS. However, with each json file that we added, our Android release build time increased by a few minutes, with our total build time exploding from ~5 minutes to ~50 minutes.

Hermes version: 0.70.4 React Native version (if any): 0.70.4 OS version (if any): MacOS Monterey 12.5.1 Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm

Steps To Reproduce

  1. Add multiple very large json files to your project
  2. Try to build your app for release on Android
  3. Notice the enormous difference in total build time

The Expected Behavior

Android build time changes minimally like is the case with metro bundling and iOS release builds.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (13 by maintainers)

Most upvoted comments

Reopening the task as the initial method we used to repro was flawed. We are now able to repro the issue, and have attributed the source to the slowdown @tmikov originally hypothesized: slow deduplication

@mmmoussa Unfortunately I can’t get this to repro. I built a fresh RN app and then downloaded the JSON file you linked and pasted it 6 times, changing some random values around. I then require’d the files inline in the App.js file and grabbed some random elements from each array, summed them up, and displayed the result. Running ./gradlew bundleRelease finished in 2mins.

Yes, they are all exactly the same but with different numbers

Based on @tmikov’s suggestion in #135, I changed all of our json files into js files that export the data as a string and then used JSON.parse in the code. Bundling is now back to being fast.

We are using hermes on iOS as well

Sorry, I should’ve provided that upfront. Here’s a sample file: https://drive.google.com/file/d/13Wa02PbEmipfmVPHxX2VklLnc-lP84-J/view?usp=sharing