[TIMOB-15756] Android: Ti.File.exists() slow performance
GitHub Issue | n/a |
Type | New Feature |
Priority | High |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 3.1.3 |
Fix Version/s | n/a |
Components | Android |
Labels | SupportTeam |
Reporter | Vladimir S |
Assignee | Unknown |
Created | 2013-11-04T18:36:32.000+0000 |
Updated | 2018-02-28T20:04:04.000+0000 |
Description
Problem Description
I just noticed that calling Ti.File.exists() on a file that is missing is quite costly in Android (on Galaxy S4). The folder contains only one file, and I am trying Ti.Filesystem.getFile('wrongfile').exists(). It takes 500-600 ms for this call to complete. In comparison Ti.Filesystem.getFile('wrongfile').getSize() returns 0 immediately.
Workaround
Use Ti.Filesystem.getFile('wrongfile').getSize() instead of exists
Comments
JSON Source
Hi Vladimir S, Could you share some simple app.js code so that i reproduce this issue. Thanks,
The TiResourceFile exists() method does a directory listing if the file does not exist in order to check if the file is a directory. This directory listing seems to be slow (maybe only on large directories). Possible solutions within the Titanium framework: 1. Add an (optional) argument "checkForDirectories" to the exists method and only check for directory if really needed 2. Check if there are more efficient solutions to see if a file is an existing directory
[~philet] Can you give an example of what is slow? What is the difference between a file in a directory with only one file and a directory with 1000 files.
Hi Ingo On a Galaxy Nexus Phone with SDK 3.2.3 it does not seem to make a difference if a directory with 1000 files is checked or a directory with 1 file. If the file does not exist, it is slow (around ~70ms). If the file exists, it is fast (<1ms). See my code and the results below. Thanks & Regards, Philippe app.js
Results: