Skip to main content
Participating Frequently
June 18, 2013
Question

File.copyTo (and copyToAsync) extremely slow on Android. e.g. 1/2 second per tiny XML file. Help?

  • June 18, 2013
  • 2 replies
  • 6586 views

On first launch, my app copies about 100 tiny XML files from application dir to storage dir. It takes about 35 seconds. That is clearly an issue. It takes about 1/100th of a second on any other platform. I've switched to copyToAsync() so that the user doesn't bail, but still this is like using a dial-up modem! Anyone have any thoughts?

This topic has been closed for replies.

2 replies

Abhinav_Dhandh
Adobe Employee
Adobe Employee
June 20, 2013

Hi Allan

I tried to reproduce this issue in which I have copied 100 XML's from application directory to applicationStorage directory in Android AIR app. The issue is not reproducible as the files were copied almost instantaneously within 1-2 seconds.

I have shared my sample project here :  https://dl.dropboxusercontent.com/u/184715790/Shared/FileCopyToTest.zip

Additionally, I have also attached the .apk : https://dl.dropboxusercontent.com/u/184715790/Shared/FileCopyToTest.apk

You could try it out and confirm if the issue is still visible.

Also could you inform about your device, OS version & AIR version which you are using ?

Regards,

Abhinav

Participating Frequently
June 21, 2013

Hi Abhinav -

I notice that my test is Flex. Your test is pure AS3. You are also using the beta 3.8 release, not an official public release?

I will get the 3.8 beta. Could you also build a 3.7.1 Flex test? Or test the one I sent via Gen?

Thanks,

Allan

jadams602
Inspiring
August 7, 2013

Just to chime in that I also am seeing very slow copyTo and copyToAsync performance on Android.

I am using the very latest AIR 3.8 beta SDK July 30th 3.8.0.1040

The use case is something we are commonly required to do on Android:

Showing local HTML help files with a StageWebView.

As you probably know, one cannot load local files on Android from File.applicationDirectory with nativePath because this is null on Android (loading from here without copying is fine on iOS however)

So in order to load local HTML help on Android in StageWebView one needs to first do:

var source:File = File.applicationDirectory.resolvePath("help");

var destination:File = File.applicationStorageDirectory.resolvePath("help");

source.copyToAsync(destination, true);

and then one can successfully load HTML files from the destination dir using nativePath URL

I have about 170 small size files in total under 'help/', a mix of some .html and some .jpeg images used in the .html totalling 6 MB in size

On *both* a Kindle Fire and on a Google Nexus 7, this single call to copyToAsync from one directory 'help' File to a new destination directory 'help' File takes a little over 20 seconds.

Fortunately I only have to do this on first viewing of help in the app, but is the slowness a result of how the compressed directory in the .apk is doing a file by file lookup and uncompress as opposed to being able to extract all files of the parent directory in one go?

Am I better off having the full help actually stored in the .apk as a .zip resource and doing a single file copy of the .zip and then an external uncompress? Or is there a way for your internal access of files within File.applicationDirectory to  optimize a full directory and all its children when the source directory File is in the .apk?

Adobe Employee
June 19, 2013

One reason could be that the Android package is a zipped format, thus copying a folder, with multiple files, from app directory, requires extracting the zipped bytes for each file in the folder, unzipping it, and then copying it to the destination.

Though it would be great if you could file a bug with a sample application (with code) do that we could reproduce and analyze at our end.

Thanks,

Daman