Android Hardware Acceleration - to use or not to use?
Asked Answered
D

3

47

I'm developing an app that it functionality very similar to Facebook Android native app: social network that most of the time the user will spend in an endless ListView displaying lot's of images, entering an image gallery, and so on.

let's say for the discussion that I'm doing all the right things and best android practices to achieve smooth scroll (recycling views as it should, using different view types when needed, loading to memory only scaled bitmaps in the needed size, caching bitmaps, using ViewHolder design pattern, not blocking th UI thread when its possible and so on...)

let's say also that every thing else in my app written in the best way and following best practices (for the discussion... :->)

my app working not bad at all in that stage, but when turning on the hardware acceleration, as described and promised in Android Developers documentation it making my app much much more smooth and fast.

let's say that it does not affect in any nagative way on the UI as can happened, and I'm not performing any of the Unsupported Operations

according to Google's document on the subject, only reason I can see not to use this feature (besides all other reasons I already mentioned above) is that it can cause my app to use more RAM. but how much RAM? a lot more? I know that when my app consumes lot's of RAM - it becoming good candidate to be destroyed by the OS when it need to free some memory.

my question is basically -

  • is it "ok" under my circumstances to use this feature?
  • what other problems can raise from using it?

TIA

Dhu answered 8/5, 2013 at 4:18 Comment(0)
P
44

To use or not to use

It is advised to use hardware acceleration only if you have complex custom computations for scaling, rotating and translating of images, but do not use it for drawing lines or curves (and other trivial operations) (source).

If you plan on having common transitions and also given that you have already considered scaling, recycling, caching etc, than it may not make sense to burden your project anymore. Also, any efforts spent reworking your code to support hardware acceleration will not effect users on versions below 3.0, which are ~36% of the market as of May 8, 2013.

Memory

Regarding memory usage (according to this article), by including Android Hardware the application loads up the OpenGL drivers for each process, takes memory usage of roughly 2MB, and boosts it to 8MB.

Other issues

Apart from API versions, I presume it will also affect battery life. Unfortunately there aren't any benchmarks on different use cases online in order to draw a line on this one. Some argue that in given cases because of multiple gpu cores, using acceleration may save battery life. Overall, I think it would be safe that the effect won't be too dramatic (or Google would have made this a major point).

Photocathode answered 8/5, 2013 at 5:1 Comment(5)
thanks for your answer. you wrote that my app will not be compatible with android pr-honeycomb, but I think that's not true: as long as the target is 11+ - you can use this feature, but it just won't do anything if the app runs on older platform. for now I only upvoted your good answer and did not accept it, because I'd like to have a chance to get more explentations..Dhu
According to developer docs : Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline is designed to better support hardware acceleration. This post might help for support below API level 11 - https://mcmap.net/q/372731/-hardware-acceleration-flagAgminate
@TalKanel fair point, you are right - it won't produce incompatibility, I have edited my answer accordinglyAnana
Another consideration is wether your are planning on playing video, and how. For example, to this date, most Android phones will not play HTML5 video if hardware acceleration is not turned on (so if your app is using a webview and you plan on using video hardware acceleration is pretty much mandatory).Unofficial
Should I use hardware acceleration when processing video?Gyro
A
13

UPDATE

Hardware acceleration is enabled by default if your Target API level is >=14


I would say yes in your situation, use hardware acceleration.

Seeing that you aren't using any resource intensive controls in your app it should not be a problem to enable Hardware acceleration. As you said your app is working quite well without hardware acceleration.

When you enable hardware acceleration Android will start using your GPU and because of the increased resources required to enable hardware acceleration, your app will consume more RAM.


A frequently asked question is Will the amount of ram increase by a really big amount?

The answer to that will all be determined by :

1. Your programming ability ie. management of the recycling list, scaling of the Images ect.

2. The Device

I wrote a app a while ago that was used to edit really high res bitmaps. I ran into the same problem. I found that on different devices the max amount of ram allocated by the OS when hardware acceleration is enabled varies by device. If your device has more ram the OS will allocate more ram to your app, so you will never find a consistent amount of ram used for your app. The bigger more expensive devices will always run your app on a larger amount of ram.


What other problems can raise by using hardware acceleration?

Hardware acceleration might cause problems for some 2D drawing operations. If you experience this you can enable Hardware Acceleration for only specific activities in your app like stated on the Hardware Acceleration post in the android Developer Docs

The easiest way to enable hardware acceleration is to turn it on globally for your entire application. If your application uses only standard views and Drawables, turning it on globally should not cause any adverse drawing effects. However, because hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your applications that use custom views or drawing calls. Problems usually manifest themselves as invisible elements, exceptions, or wrongly rendered pixels. To remedy this, Android gives you the option to enable or disable hardware acceleration at the following levels: Application, Activity, Window, View

This way you can also limit the hardware acceleration in your app but by the sound of it you will need it for most of your apps functions.

Hope this helps

Agminate answered 8/5, 2013 at 5:11 Comment(2)
+1 for the insight on different RAM consumption on different devices. @neil Do you have any approximate numbers to share as a general reference point?Anana
If I had to write down numbers now I would lie! I never took down the consistencies of ram differences by device. I just know that the amount of ram allocated by a device with 500MB of ram is noticeably less than a device with 1GB of ram. The ram allocation for the app might also be affected by other apps running in the background and the available amount of ram but that is an assumption made by everyone.Agminate
A
0

Accordion my stats its made %10 performance improvment for React Native App.

Performance Summary: hardwareAccelerated:true hardwareAccelerated:false

Ram: True False

FPS: True False

CPU: True False

Artemas answered 1/7 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.