1

I have some expensive computations to do in JS in a React Native project where I need to use a lot of pre-computed datas.

I have exported these in JSON files (each ~2MB) that I'm loading when I need them like so :

export const getDataShootAngle = () => {
    return [
        require('./parsed_phi1.json'),
        require('./parsed_phi2.json'),
        require('./parsed_phi3.json'),
        require('./parsed_phi4.json'),
        require('./parsed_phi5.json'),
        require('./parsed_phi6.json'),
    ];
};

But when I do this I get the error :

Error: Requiring module "algorithm\data\parsed_phi6.json", which threw an exception: RangeError: Maximum call stack size exceeded, js engine: hermes

Is there a way to load big amount of data in React Native ? I would be okay to export my data in a binary format but I have no idea of how I would do this.

Also, I guess it would be nice if I could only load the data once it's needed (kinda what I tried to do with the require() directly inside of a function instead of using an import at the top of the file).

Edit : I am using Expo to develop my app so I was testing it using Expo Go. I just tried to compile it to an .apk and it turns out the bug doesn't come in this context. I guess this is a limitation with Expo Go, would be nice if there was still a way to debug the app though.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TOOL
  • 70
  • 1
  • 10
  • What platform? Sim/emulator/device? There's a potential solution for Android here: https://stackoverflow.com/questions/39655791/out-of-memory-application-crash-react-native. You could try storing the json files into separate variables; I don't know how JS loads stuff under the hood but splitting may make it easier for it to split up the memory usage. 12 MB doesn't seem like a lot, so there might be something else going on, too. Anything else loading in your app? Have you tried using the profiling tools in Xcode/Android Studio to look at what's using memory? – Abe May 10 '22 at 04:03
  • @Abe I am using Expo and was testing the app with Expo Go on my Android phone. I just tried to compile the app to an `.apk` and now the bug is gone. I wish I could still test the app on Expo Go though. I updated my post with these informations. – TOOL May 10 '22 at 08:17

1 Answers1

0

I managed to fix that myself.

The problem was comming from using the Hermes engine instead of jsc.

I don't know what caused it, but at least I can continue to work on my app.

To change back to the default, I replaced hermes by jsc in my app.json file :

// app.json
{
    "expo": {
        ...
        "jsEngine": "jsc",
        ...
    }
}
TOOL
  • 70
  • 1
  • 10