Search code examples
androidoptimizationinlinerenderscript

How do I spot-optimize code for the Android platform?


I'm an iOS developer and I'm considering getting into Android development.

In Objective-C, I'm used to being able to optimize and tune specific hotspots (e.g. image processing) using inline directives and low-level code.

How do I do the same in Android? Is the answer Renderscript? Is Renderscript compatible with all Android devices?

At a minimum, can I specify that certain methods should be inlined to save on procedure calls in extremely, extremely tight loops?


Solution

  • How do I do the same in Android?

    If by "the same" you mean "using inline directives and low-level code", generally you don't "do the same". There is no "inline directive" in Java. You are welcome to use the NDK to add native code to your Android app.

    Is the answer Renderscript?

    Renderscript Compute can be used to improve performance of things that Renderscript Compute is good at, and image processing tends to be one (at least for some types of processing, like filters).

    Is Renderscript compatible with all Android devices?

    AFAIK it should be available on all Android devices running API Level 11 and higher (a.k.a., Android 3.0+).

    can I specify that certain methods should be inlined to save on procedure calls in extremely, extremely tight loops?

    No. The Dalvik JIT will detect and optimize such code based on its own internal heuristics.