[TIMOB-26144] Android: Improve File.getDirectoryListing() performance in Resources directory
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-09-19T21:34:26.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.5.0 |
Components | Android |
Labels | File, Filesystem, android, performance |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2018-06-21T02:28:01.000+0000 |
Updated | 2018-10-09T10:40:18.000+0000 |
Description
*Summary:*
On Android, accessing files/directories under "Resources" is slower than it should be. These files are stored within the APK where a list of file paths from "assets" can be easily extracted... which should make it faster than storage access.
*Test:*
Run the below code to fetch a listing of all files under the "Resources" directory. Observe the log for the duration of this function.
var startTime = new Date();
var file = Ti.Filesystem.getFile(Ti.Filesystem.getResourcesDirectory());
var listing = file.getDirectoryListing();
Ti.API.info("@@@ getDirectoryListing() duration: " + (new Date() - startTime));
*Results:*
For a project have about 160 files under "Resources", I get the following results...
* Android 4.1 Emulator: 80 ms
* Galaxy Nexus (Android 4.1): 70 ms
* Amazon Fire HD 8 (7th Generation): 19 ms
* Pixel XL (Android 8.0): 3 ms
*Recommended Solution:*
An Android APK is really a zip file. We should open the APK as a zip file and fetch/store all zip entries referencing files under the "assets" directory. This way we can have fast hash table lookups when doing existence checks and fetching directory listings.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10112
The above PR makes
getDirectoryListing()
calls under the "Resources" directory about 20x faster. Below are test results doinggetDirectoryListing()
with a directory having about 150 files. Shows old time -> new time.FR Passed.
getDirectoryListing()
timing seems to have improved significantly. Studio Ver: 5.1.1.201809051655 SDK Ver: 7.5.0 local build OS Ver: 10.13.5 Xcode Ver: Xcode 9.4.1 Appc NPM: 4.2.13 Appc CLI: 7.0.6 Daemon Ver: 1.1.3 Ti CLI Ver: 5.1.1 Alloy Ver: 1.13.2 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 10.0.2 Devices: ⇨ google Nexus 5 (Android 6.0.1) ⇨ google Pixel (Android 9) Emulator: ⇨ Android 4.1.2PR Merged.
*Closing ticket.* Fix can now be verified in SDK version
7.5.0.v20181008124804.
Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/10112