Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read/write extremely slow on IOS #474

Open
alainib opened this issue Apr 12, 2018 · 17 comments
Open

Read/write extremely slow on IOS #474

alainib opened this issue Apr 12, 2018 · 17 comments

Comments

@alainib
Copy link

alainib commented Apr 12, 2018

I'm writing a 5mo json in a file with utf8 encoding.

  1. it's very slow on IOS

it take +-50ms with android
it take +-6000ms with ios iphone 5

reading the file take
250ms with android
13000ms with ios.

  1. i get empty return when using base64 option on Ios only

  2. my code :

       var RNFS = require('react-native-fs');
       const rootPath = RNFS.DocumentDirectoryPath; //= (os == "android") ? RNFS.DocumentDirectoryPath :RNFS.MainBundlePath
    
       export function writeFile(filename, content) {
         var path = rootPath + '/' + filename;
         return RNFS.writeFile(path, content, 'base64').then(() => {
           console.log('FILE WRITTEN!');
           return true;
         }).catch((err) => {
           console.log(err.message);
           return false;
         });
       }
    
       export async function readFile(filename) {
         var path = rootPath + '/' + filename;
         var content = await RNFS.readFile(path, 'base64');
         console.log("content before return", content );
         return content;
       }
    

and how i made the calls

      async readFile() {
        const content = await tools.readFile("en-test.js");
        console.log("content", content);
      }

  
      async writeFile() {
        const res = await tools.writeFile(
          "en-test.js",
          'Lorem ipsum dolor sit ametLorem ipsum dolor sit ametLorem ipsum dolor sit ametLorem ipsum dolor'  
         );
        console.log("res", res);
      }

I need to keep utf8, any advice ?

@itinance
Copy link
Owner

We definetely should move the utf8-encoding into native layer instead of using JS-layer therefor.
This should be implemented in upcoming versions

@gtebbutt
Copy link

gtebbutt commented Oct 9, 2018

@itinance Firstly, thank you for all your work on the library!

I was wondering if there's a plan on moving the encoding into native on iOS? I did a very rudimentary test (literally just changed the default return type in the native code) and it looks like a 10x or greater speedup on large files.

All I did was swap [content base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]; with [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding];, but I haven't yet looked at Android or at the implications of changing the function signature to pass the encoding back to the native code.

@kesha-antonov
Copy link

Is this fixed?
Animations in my app stattering when I do RNFS.readFile

@alainib
Copy link
Author

alainib commented Oct 25, 2018

not fixed for me. read and write freeze complety the UI for many seconds. not usable unfortunably

@tgensol
Copy link

tgensol commented Jan 20, 2019

Same here

@jan-happy
Copy link

+1

@alainib
Copy link
Author

alainib commented Mar 13, 2019

any update ?

@kesha-antonov
Copy link

I use RN-fetch-blob for read/write files

@ATShiTou
Copy link

I use fetch to read/write files:

const res = await fetch(filePath);
const content = await res.text();

@schumannd
Copy link

schumannd commented Apr 3, 2019

Can confirm that there is a significant difference between android and iOS.

This issue also affects e.g. the hash() function.

Edit: We were (and still are) actually using rn-fetch-blob. I was testing react-native-fs because our package was having issues. But this bug sent me straight back. Seems like a pretty big deal breaker to me.

@alainib
Copy link
Author

alainib commented Apr 4, 2019

I use fetch to read/write files:

const res = await fetch(filePath);
const content = await res.text();

how did you write file with fetch ?
thanks

@alainib
Copy link
Author

alainib commented Apr 4, 2019

Can confirm that there is a significant difference between android and iOS.

This issue also affects e.g. the hash() function.

I will test it today when i get the Mac back

@xvonabur
Copy link

Same problem. Downloading on iOS is extremely slow even on LAN connection.

@russelRajitha
Copy link

uploadings getting slow with uri.

@creambyemute
Copy link

creambyemute commented Oct 31, 2019

I also had to switch to rn-fetch-blob for iOS and Android due to the encoding happening in the JS Thread and in our case, blocking the App/Interactions for around 4 seconds.

Works fine with rn-fetch-blob which does the encoding natively

I'd move the encoding to native for this library with a PR, but atm I'm pretty occupied.

@robert-bitguild
Copy link

I got same situation when I read 3M file from IOS device. It takes 1.2 seconds to read it. I don't know what does it read file in js thread

@xaiamov
Copy link

xaiamov commented Aug 9, 2023

This library is absolutely useless for dealing with files bigger than 1M. The reason – it doesn't work with binary data and converts to base64, which is slow.

I am switching to https://github.com/joltup/rn-fetch-blob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests