LightMind commented on issue #364: URL: https://github.com/apache/cordova-plugin-file/issues/364#issuecomment-776921222
I have implemented the chunking behaviour in [FileWriter.js](https://github.com/LightMind/cordova-plugin-file/blob/master/www/FileWriter.js). It seems pretty necessary to do chunking, because even though we skips the `args[i] = base64.fromArrayBuffer(args[i]);` part, cordova.js still calls `JSON.encode` on all the params we want to pass to the native layer. This does not go so well for several megabyte of data. I tried with chunks of 128KiB, 1MiB, and 5MiB. Larger chunks are faster to write, having less downtime between writes, but the memory spikes are worse. Memory usage is mostly due to `JSON.encode`, as far as I can debug. When writing one chunk of 5 MiB, my android-phone would use about 30 MiB. Speeds were around 4.5 to 4.8 MiB/second ( measured from calling FileWriter.write, to succesCallback ). Writing 5MiB chunks looks like this:  When writing 1MiB chunks, there is more downtime, but much less memory pressure. Spikes of less than 10MiB memory usage, and write speed is between 4.2 to 4.5. So, sligthly slower, but more stable. Writing smaller chunks does not make sense, as the downtime between writes is too much, halving the write speed at chunks of 128KiB. I have some questions, but I'll take that when I make a PR, which I will do soon. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
