Android Performance Tip

When developing high performance code for android there are already a lot of tips on the web to use. One thing I learned today: Don't believe other people's suggestions on performance if you haven't tried it out yourself. One common misconception I came across multiple times for example is that it is a negligible trade-off when you use ArrayList instead of a real, Java array. For me, this wasn't true. Replacing an ArrayList with the Java array at performance critical parts of my code resulted in an overall 20% speed increase! I think one reason for this also might be that I used arrays of primitive types. When they are in the ArrayList, each type again is wrapped in a wrapper type (like 'Integer' for 'int'), probably also causing an additional impact. So yes, arrays are faster than ArrayList. Sometimes.

two comments, already:

Interesting I have actually found both Array List and Java Array to be faster in certain circumstances also.
Justin (link) - 05 11 12 - 06:00

A native array of primitive types will always be faster than an ArrayList, no matter what. This might or might not apply to reference types, but for primitive types it’s a simple consequence of Java’s retarded type system. It always requires boxing/unboxing in this case, so it can’t be as fast as a native array.
Michi - 08 11 12 - 19:38

Displayed name:  
Remember personal info?
Website (optional):
Enter "layered" (antispam):
Comment:Emoticons / Textile


Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Note: If you type in your email adress above, it will be visible to other visitors, although it will be hidden for bots using javaScript.