itinance / itinance/react-native-fs

Read/write extremely slow on Android

Open
#388 7 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I'm not sure exactly what's going on, but shouldn't writing/reading files be significantly faster than the below quick test? And shouldn't read by faster than write, not slower?

I think I might be doing _something_ wrong.

The reason I'm asking is that I've got a pretty big JSON object, around 4 MB, I need to store in the app. And since it's > 2 MB I can't use AsyncStorage on Android. So I want to save it to a file, and read it on startup of the app. But the loading time of several seconds isn't gonna fly with the user base.

**result on a new, clean Pixel 2.**
```
11-18 12:26:10.726 5592 7953 I ReactNativeJS: str is 4198400 bytes (4.00 MB)
11-18 12:26:10.726 5592 7953 I ReactNativeJS: starting write
11-18 12:26:14.381 5592 7953 I ReactNativeJS: write done in 3.654 (1.10 MB/s)
11-18 12:26:14.381 5592 7953 I ReactNativeJS: starting read
11-18 12:26:21.333 5592 7953 I ReactNativeJS: read done in 6.951 (0.58 MB/s)
```

```js
var RNFS = require('react-native-fs');

var file = {
test: async function(){

var uri = RNFS.DocumentDirectoryPath + "/test.txt";

//generate str
var str = "";
for (var i=0;i<1024;i++) {
str += "a";
for (var n=0;n<1024;n++) {
str += "b";
}
}
str += "";
var megs = str.length / 1024 / 1024;
console.log(`str is ${str.length} bytes (${megs.toFixed(2)} MB)`);

//write test
var now = Date.now();
console.log("starting write");
await RNFS.writeFile(uri, str);
var secs = (Date.now() - now)/1000;
console.log(`write done in ${secs} (${(megs/secs).toFixed(2)} MB/s)`);

//read test
now = Date.now();
debug.dd("starting read");
str = await RNFS.readFile(uri);
secs = (Date.now() - now)/1000;
console.log(`read done in ${secs} (${(megs/secs).toFixed(2)} MB/s)`);

}
};

await file.test();

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.