Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26144] Android: Improve File.getDirectoryListing() performance in Resources directory

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2018-09-19T21:34:26.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.5.0
ComponentsAndroid
LabelsFile, Filesystem, android, performance
ReporterJoshua Quick
AssigneeJoshua Quick
Created2018-06-21T02:28:01.000+0000
Updated2018-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.

Comments

  1. Joshua Quick 2018-06-21

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10112
  2. Joshua Quick 2018-06-21

    The above PR makes getDirectoryListing() calls under the "Resources" directory about 20x faster. Below are test results doing getDirectoryListing() with a directory having about 150 files. Shows old time -> new time.
       Android 4.1 Emulator: 80 ms -> 3.0 ms
       Galaxy Nexus:         70 ms -> 2.5 ms
       Amazon Fire HD 8:     19 ms -> 1.0 ms
       Pixel XL:              3 ms -> 0.5 ms
       
  3. Lokesh Choudhary 2018-09-17

    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.2
  4. Lokesh Choudhary 2018-09-19

    PR Merged.
  5. Samir Mohammed 2018-10-09

    *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

JSON Source