Android Performance: readStream takes too long #321
Description
Library version: 0.10.4
RN Version: 0.41.1
I have a JSON file, inside my assets directory in the android version.
The file is 8MB. I am reading the file using the following function:
const path = RNFetchBlob.fs.asset('app_data.json');
return RNFetchBlob.fs.readStream(path, 'utf8')
.then((stream) => {
let data = ''
stream.open()
stream.onData((chunk) => {
data += chunk
})
stream.onEnd(() => {
dispatch({ type: APP_DATA.SUCCESS, payload: JSON.parse(data) });
})
})
The above function takes about 15 seconds to execute on Android, and about 2 seconds on iOS.
Is there any obvious reason why this is happening ? Any optimisations I can make ? Should I increase the buffer, or make changes to the way the file is stored?
The file is loaded once when the application launches, there are no animations or anything interactive while this process takes place, just a loading screen with a gif image
readFile is also taking about the same amount of time.
I have tried tinkering with interval / buffer size, but the loading time does not appear to be affected.. Also the JSON.parse does not appear to add any additional overhead.
By changing the buffer size / interval, the loading time either stays the same, or can get worse, but no improvements.
iOS goes through the same loading screen in about 0.5 sec..
The delay is between promise.resolve(data) being called from Android, and the data reaching my code.