Android version very slow getting resources

Android version very slow getting resources
0.0 0


I was really disturbed because my application was getting very slow in android. I had a iOS version which was much faster.

My application has a lot of resources (~12000).
It takes less time getting resources which name starts with “a” than resources which name starts “z”.

I realized that, in Android, to get a resource, cocos2d-x uses “CCFileUtils::getFileDataFromZip”, which uses “unzLocateFile” from “support\zip_support\unzip.cpp”. Here, I found this code:

while (err == UNZ_OK)
char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
err = unzGetCurrentFileInfo64(file,NULL,
if (err UNZ_OK)
if (unzStringFileNameCompare(szCurrentFileName,
return UNZ_OK;
err = unzGoToNextFile(file);

This code explains why “z**" files take more time than "a**” files…
In iOS I don’t have this problem…

What can I do to optimize resources access?

Thanks in advance


You can try using spritesheets to combine small images into one file.


Thanks, but it’s not a good idea for my application. These images are 256-height.


Proper solution would be that Cocos2d-x fills a std::map at startup parsing all files and caching zip offset to pass to zLib.
This way any file could be accessed very quickly, but that would certainly slow up startup time a lot.


Yes Romain, you’re right… I already tested it, and it slows up startup time…
I’m trying to get file data using jni and getAssets(). I’ll let you know if this approach is successfully.


I received this in my email:

cocos2d-x - C++ Framework: RE: Android version very slow getting resources Victor Komarov What version do you use? I think updating to the latest version from github will help, your issue was discussed here:

I think this answer was deleted (don’t know why…), but it is correct!
Version 2.1-beta makes my android version as faster as iOS version.

Thanks a lot!