Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3040] Android: If image stored directly in Resources/images, referencing it causes too many unnecessary exceptions

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-05-05T15:21:15.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-12
ComponentsAndroid
Labelsandroid, defect, release-1.7.0, reported-1.5.1
ReporterBill Dawson
AssigneeBill Dawson
Created2011-04-15T03:35:18.000+0000
Updated2011-05-05T15:21:15.000+0000

Description

"Failcase" is, for example, the Table View Layout 2 test in KitchenSink. It's not really a "failure" since the test actually works. But behind the scenes a bunch of exceptions -- handled exceptions -- are happening, very likely affecting performance.

You can see it happening if you run KS with <property type="bool" name="ti.android.debug">true</property> in tiapp.xml. Run adb logcat at the command line, then -- with KS running in your emulator -- go to the Views -> Table Views -> Layout 2 test. As the test loads, watch logcat scrolling by -- you'll end up seeing a ton of exceptions. If you then scroll up and down on the table view in the test, you'll see a ton more exceptions being logged in logcat.

Alternatively, you can watch me doing it here:

http://screencast.com/t/FD9E6klYe">http://screencast.com/t/FD9E6klYe

What's happening is this: Because the image path begins with Resources/images -- which is one of our standard locations to check for density-specific images -- we do the density image name mangling and check to see if the image exists as an Android resource. The checking to see if it's a resource uses reflection (see TiRHelper.locateResource), and has to accept the fact that an exception will be raised if the resource doesn't exist. It handles that fine (and sends it to logcat if debug is turned on -- which is what we're seeing in that video) and the result is that our loadDrawable method ends up successfully finding the image file in the standard file system. But I imagine those exceptions are expensive. The problem is that -- unlike successful finds of a resource image -- we do not cache the failures. So it tries every time to load the same image as a resource that doesn't exist.

I think putting images into the Resources/images folder is probably a fairly common pattern for app developers. So we could perhaps improvement performance for these people by caching resource lookup failures to avoid going through the series of exceptions over and over again.

Comments

  1. Bill Dawson 2011-04-15

    (from [b47d085bb43a5bc9b885ee89d7067eddccbbc8db]) When looking up Resource/android/images/xxx images in the android resources, don't bother checking for android system resources, since by definition you're looking for a project-specific resource. Saves one lookup. [#3040] https://github.com/appcelerator/titanium_mobile/commit/b47d085bb43a5bc9b885ee89d7067eddccbbc8db"> https://github.com/appcelerator/titanium_mobile/commit/b47d085bb43a...

  2. Bill Dawson 2011-04-15

    Hmm, as usual one of my commits not listed automatically. The main commit for this item is:

    https://github.com/appcelerator/titanium_mobile/commit/e7beec84f5209141bd"> https://github.com/appcelerator/titanium_mobile/commit/e7beec84f520...

  3. Bill Dawson 2011-04-15

    QE Testing: follow the elaborate :) instructions up in the description, and (in the pre-fix version of the SDK) you'll see a bunch of exceptions scrolling by in logcat (they will be categorized as "TiRHelper"). Then, after installing the fixed version, you won't see those exceptions anymore.

JSON Source