• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

[UPDATE] Android insights: HW Acceleration, performance, Lags

samrox144

Android Expert
Feb 26, 2011
1,122
265
Bangalore
Hi @all,


I think its a good idea to post here nice and interesting articles - this can help the devs here but the users to why
sometimes its simply impossible to code things or fix things.

Please dont spam this thread, even its in general section - let users read interesting things instead of pages full of shit

"The Reason Android is Laggy"

Dianne starts off her post with a surprising revelation:
 
A new one

dianne hackborn - 00:38 (edited) - public
a few days ago i wrote a post trying to correct a lot of the inaccurate statements i have seen repeatedly mentioned about how graphics on android works. This resulted in a lot of nice discussion, but unfortunately has also lead some people to come up with new, novel, and often technically inaccurate complaints about how android works.

These new topics have been more about some fundamental design decisions in android, and why they are wrong. I’d like to help people better understand (and judge) these discussions by giving some real background on why android’s ui was designed the way it is and how it actually works.

One issue that has been raised is that android doesn’t use thread priorities to reduce how much background work interrupts the user interface. This is outright wrong. It actually uses a number of priorities, which you can even find defined right here http://developer.android.com/referen...priority_audio in the sdk.

The most important of these are the background and default priorities. User interface threads normally run at the default priority; background threads run in the background priority. Application processes that are in the background have all of their threads forced to the background priority.

Android’s background priority is actually pretty interesting. It uses a linux facility called cgroups to put all background threads into a special scheduling group which, all together, can’t use more than 10% of the cpu. That is, if you have 10 processes in the background all trying to run at the same time, when combined they can't take away more than 10% of the time needed by foreground threads. This is enough to allow background threads to make some forward progress, without having enough of an impact on the foreground threads to be generally visible to the user.

(you may have noticed that a “foreground” priority is also defined. This is not used in current android; it was in the original implementation, but we found that the linux scheduler does not give enough preference to threads based on pure priority, so switched to cgroups in android 1.6.)

i have also seen a number of claims that the basic android design is fundamentally flawed and archaic because it doesn’t use a rendering thread like ios. There are certainly some advantages to how ios work, but this view is too focused on one specific detail to be useful, and glosses over actual similarities in how they behave.

Android had a number of very different original design goals than ios did. A key goal of android was to provide an open application platform, using application sandboxes to create a much more secure environment that doesn’t rely on a central authority to verify that applications do what they claim. To achieve this, it uses linux process isolation and user ids to prevent each application from being able to access the system or other application in ways that are not controlled and secure.

This is very different from ios’s original design constraints, which remember didn’t allow any third party applications at all.

An important part of achieving this security is having a way for (edit: It has been pointed out to me that ios does in fact use multiple windows and multiple gl contexts. Lesson to me, just don't talk about anything i haven't directly verified. That still doesn't change things for android, though, where as i mention later we simply did not have hardware and drivers that could do multiple gl contexts until fairly recently.)
individual ui elements to share the screen in a secure way. This is why there are windows on android. The status bar and its notification shade are windows owned and drawn by the system. These are separate from the application’s window, so the application can not touch anything about the status bar, such as to scrape the text of sms messages as they are displayed there. Likewise the soft keyboard is a separate window, owned by a separate application, and it and the application can only interact with each other through a well defined and controlled interface. (this is also why android can safely support third party input methods.)

another objective of android was to allow close collaboration between applications, so that for example it is easy to implement a share api that launches a part of another application integrated with the original application’s flow. As part of this, android applications traditionally are split into pieces (called “activities”) that handle a single specific part of the ui of the application. For example, the contacts lists is one activity, the details of a contact is another, and editing a contact is a third. Moving between those parts of the contacts ui means switching between these activities, and each of these activities is its own separate window.

Now we can see something interesting: In almost all of the places in the original android ui where you see animations, you are actually seeing windows animate. Launching contacts is an animation of the home screen window and the contacts list window. Tapping on a contact to see its details is an animation of the contacts list window and the contacts details window. Displaying the soft keyboard is an animation of the keyboard window. Showing the dialog where you pick an app to share with is an animation of a window displaying that dialog.

When you see a window on screen, what you are seeing is actually something called a “surface”. This is a separate piece of shared memory that the window draws its ui in, and is composited with the other windows to the screen by a separate system service (in a separate thread, running at a higher than normal priority) called the “surface flinger.” does this sound familiar? In fact this is very much like what ios is doing with its views being composited by a separate thread, just at a less fine-grained but significantly more secure level. (and this window composition has been hardware accelerated in android from the beginning.)

the other main interesting interaction in the ui is tracking your finger -- scrolling and flinging a list, swiping a gallery, etc. These interactions involve updating the contents inside of a window, so require re-rendering that window for each movement. However, being able to do this rendering off the main thread probably doesn’t gain you much. These are not simple “move this part of the ui from x to y, and maybe tell me when you are done” animations -- each movement is based on events received about the finger on the screen, which need to be processed by the application on its main thread.

That said, being able to avoid redrawing all of the contents of the parts of the ui that are moving can help performance. And this is also a technique that android has employed since before 1.0; ui elements like a listview that want to scroll their content can call http://developer.android.com/referen...nabled(boolean) to have that content rendered into a cache so that only the bitmap needs to be drawn as it moves.

Traditionally on android, views only have their drawing cache enabled as a transient state, such as while scrolling or tracking a finger. This is because they introduce a fair amount more overhead: Extra memory for the bitmap (which can easily total to multiple times larger than the actual frame buffer if there are a number of visual layers), and when the contents inside of a cached view need to be redrawn it is more expensive because there is an additional step required to draw the cached bitmap back to the window.

So, all those things considered, in android 1.0 having each view drawn into a texture and those textures composited to the window in another thread is just not that much of a gain, with a lot of cost. The cost is also in engineering time -- our time was better spent working on other things like a layout-based view hierarchy (to provide flexibility in adjusting for different screen sizes) and “remote views” for notifications and widgets, which have significantly benefited the platform as it develops.

In fact it was just not feasible to implement hardware accelerated drawing inside windows until recently. Because android is designed around having multiple windows on the screen, to have the drawing inside each window be hardware accelerated means requiring that the gpu and driver support multiple active gl contexts in different processes running at the same time. The hardware at that time just didn’t support this, even ignoring the additional memory needed for it that was not available. Even today we are in the early stages of this -- most mobile gpus still have fairly expensive gl context switching.

I hope this helps people better understand how android works. And just to be clear again from my last point -- i am not writing this to make excuses for whatever things people don’t like about android, i just get tired of seeing people write egregiously wrong explanations about how android works and worse present themselves as authorities on the topic.

There are of course many things that can be improved in android today, just as there are many things that have been improved since 1.0. As other more pressing issues are addressed, and hardware capabilities improve and change, we continue to push the platform forward and make it better.

One final thought. I saw an interesting comment from brent royal-gordon on what developers sometimes need to do to achieve 60fps scrolling in ios lists: “getting it up to sixty is more difficult—you may have to simplify the cell's view hierarchy, or delay adding some of the content, or remove text formatting that would otherwise require a more expensive text rendering api, or even rip the subviews out of the cell altogether and draw everything by hand.”

i am no expert on ios, so i’ll take that as as true. These are the exact same recommendations that we have given to android’s app developers, and based on this statement i don't see any indication that there is something intrinsically flawed about android in making lists scroll at 60fps, any more than there is in ios.
 
Upvote 0
since the time of the launch of the iOS .. a few people have known that it is just a fake multi tasking.. iOS actually never does any multi tasking.. i would say my old symbian n70 was light years better in terms of multi tasking.. .... ut apple are trying to fix these in the upcoming iOSes...
dont mistake me.... i love the ANDROID.. but i still feel SYMBIAN.. is a wiser person when it comes to true multi tasking.. :)
 
Upvote 0
since the time of the launch of the iOS .. a few people have known that it is just a fake multi tasking.. iOS actually never does any multi tasking.. i would say my old symbian n70 was light years better in terms of multi tasking.. .... ut apple are trying to fix these in the upcoming iOSes...
dont mistake me.... i love the ANDROID.. but i still feel SYMBIAN.. is a wiser person when it comes to true multi tasking.. :)


True.
 
Upvote 0

What u say about the newer launched MANGO OS..?
Reviews have been told as it is more simpler than the other mobile OS's.
And yes truly it has been told in the reviews as this new OS is also better in multitasking, simpler to use and more of it is more beautiful than Android and I-OS.. .. .. .. ..
:) :)


Can it be ported on any Android handset?
 
Upvote 0
So it seems like Apple can't fight Samsung popularity in Android, and now is deciding to use dirty tricks in court, LOL

and Since when TouchWiz seems / feels like iOS? it has nothing alike

Apple is playing the cry baby now, as 2010 sales of android jumped like 200% way over taking iOS, and mostly was thanks to Samsung and all of its like of Galaxy S products.

way to go Samsung


This is what i'm referring to, check out the android activation video

http://www.youtube.com/watch?v=fqFpq9WXbJo&feature=player_embedded#at=117

READ THE REPLIES ALSO ...THEY ARE THE BEST PART

http://www.xda-developers.com/android/oh-apple-when-will-you-learn/
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones