apache / apache/cordova-plugin-file
Low performance when read large file with cordova-plugin-file
- Dominant language
- JavaScript
- Stars
- 744
- Forks
- 754
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 1
Description
am creating a hybrid app with Angular 7, Ionic 4 and Cordova.
I need to read a large file (> 1GB) located on Android file system but i am facing a performance issue. With the current implementation i have a speed about **2.5 MB/sec**.
Is it an issue with the plugin itself or the implementation ?
I tried to modify BLOB_SIZE but the maximum speed i obtained was 2.5 MB/s.
```typescript
const BLOB_SIZE = 1024*1024;
usbRead(fileEntry: FileEntry) {
fileEntry.file((file) => {
const reader = new FileReader();
reader.onload = () => {
const buffer = new Uint8Array(reader.result as ArrayBuffer);
readCounter += buffer.byteLength;
console.log(textDecoder.decode(buffer));
offset += BLOB_SIZE;
if (offset >= file.size) {
console.log('end');
return;
}
const slice = file.slice(offset, offset + BLOB_SIZE);
reader.readAsArrayBuffer(slice);
};
reader.readAsArrayBuffer(file.slice(0, BLOB_SIZE));
});
});
}
```
I tested on Xiaomi Redmi Note 7 with Android 9
My package.json has the following plugin version :
`@ionic-native/file": "^5.12.0"`
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Contributor guide
Research direction
Reproduce the reported read loop on the Xiaomi Redmi Note 7/Android 9 using the supplied TypeScript code and compare results with different BLOB_SIZE values. Trace the cordova-plugin-file read path and the FileReader slicing loop to determine whether the bottleneck is in the plugin or the implementation; done means the cause and any supported limitation are established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, angular, typescript
- Domain
- mobile-dev, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100