Recent Changes‎ > ‎

Lint Performance Checks

posted Feb 23, 2012, 4:01 PM by Tor Norbye   [ updated Feb 23, 2012, 4:20 PM ]
Some of the new lint checks in ADT 17 are aimed at finding performance issues.

The DrawAllocation detector finds cases where you are allocating new objects during a paint, layout or measure method (and you're not doing it just once via lazy initialization). The recommended way to do this is to preallocate any objects you need during a drawing operation, or to initialize them lazily and reuse for each paint. If not, you'll be generating a lot of garbage which can lead to UI lags.

In ADT 17 the HTML report has been revamped a bit. Here's what you see for a couple of DrawAllocation errors:
Another useful check locates cases where you're using the general HashMap class with an Integer key. Android has several optimized classes for this scenario (SparseIntArray, SparseBooleanArray, SparseArray) which you're better off using:
In a similar vein, there's a new detector which finds usages of various Math functions, such as Math.sin(). If it sees that you are converting a float to a double in order to call the function, or converting the result back from a double to a float (even if it's done implicitly - no need to have explicit casts since this detector is operating at the bytecode level), then it will suggest that you replace your call with the corresponding android.util.FloatMath method instead: