r/androiddev•
numros

Why isn't UI/animations performance on Android smooth as on iOS?

Even on high end devices with the latest processors and GPUs lack behind iOS when it comes to UI performance, specially animations and UI smoothness.

This is not a iOS vs Android rant. I feel like the UI thread has low priority, if anything else is happening on the phone frames are skipped. As a developer, I wanna bring in the discussion on what's the problem, limitations and how can I work around them to make my apps smoother/60 fps.

Posted Nov 1, 2016, 4:27 PM UTC

4533
Shaper_pmp•

Android was originally designed to be a general-purpose computing platform (background services, true multitasking, etc) and compromises were made in various systems (UI fluidity, battery management, etc) to accommodate that.

iOS was designed from the ground up to give a smooth, responsive user-interface (low input latency, smooth redraws, etc), and compromises were made on the design of the OS to accommodate that (eg, no background services or proper multitasking for a very long time etc).

It's a bit inflammatory to characterise it like this, but at a very fundamental level iOS was designed to be pretty and responsive above all else, while Android was primarily designed to be functional and flexible.

Having staked out their territory both OSs are moving to encompass the remaining functionality as best they can (Android's Project Butter, iOS slowly adding numerous multitasking APIs and background processing features), but fundamentally both are running uphill relative to their initial starting assumptions, so it's not surprising they're swimming against the flow.

There are other differences too:

iOS is pretty much a single product running on a single restricted range of hardware built from custom chips. The hardware and software are literally designed to play well together (which gives efficiency benefits, but costs you by limiting your flexibility and choice). Android is designed to be a general solution that runs on a wide variety of hardware chipsets and configurations, but at the cost that it can't possibly be as optimised for every individual configuration.

One additional possible factor is that (thanks to the restricted hardware support) iOS requires apps to be compiled to native machine code (pretty much the most efficiently executed representation of a program, but specific to a single chipset), whereas Android apps are semi-compiled to a device-agnostic "bytecode" representation, which must be interpreted at runtime by a virtual machine (originally Dalvic, now ART).

There's an inherent cost on startup/runtime in interpreting, transforming and executing bytecode compared to simply executing machine code (yes, even with JIT compilation), but with the incredible engineering in the JVM (and related technologies like Dalvik/ART) it's genuinely debatable whether this is a significant difference these days once the VM is "warmed up" and ready to go.

69
pjmlp•

ART does AOT compilation, just like iOS. On Android 5.x and 6.x.

https://source.android.com/devices/tech/dalvik/

As of Android N, it does a mix of Assembly interpreter, JIT, code cache and AOT compilation using PGO when the device is plugged.

19
Shaper_pmp•

Right you are - I'd forgotten about that. Good addition!

5
Rhed0xRX is overrated•

ART is not the issue, it's pretty damn fast.

1
BorgDrone•

ART is not an issue, but Java is. Or more specifically: garbage collection is.

3
DarkLordAzrael•

ART is not an issue, but Java is. Or more specifically: garbage collection is.

The real performance problems caused by Java aren't really the GC (which is very well tuned) but the huge amount of virtual dispatch and cache hostility enforced by the language.

2
Rhed0xRX is overrated•

The GC is part of ART and they spent a lot of time optimizing it.

1
BorgDrone•

One additional possible factor is that (thanks to the restricted hardware support) iOS requires apps to be compiled to native machine code

This is no longer true. iOS apps are compiled to LLVM bitcode, and uploaded like that to Apple. At some point the bitcode is compiled to native code, but I'm not sure if that is happening before or after the download.

2
MindInMotionMkd•

Unwritten rule: Method should not take more than 16 ms.

Identify what eats your fps? Can be text drawing, can be view layout, can be something that happens between animation update calls.

Omit calls that are not needed. Don't do allocations where drawing/layout happens. Cache everything upfront that can be cached.

15
lnkprk114•

This is all valid advice, but it doesnt address the primary question of why is it that iOS is so fluid compared to Android.

14
MindInMotionMkd•

I don't know anything about iOS. I tried iOS development once, wasn't fun at all.

3†
numrosOP•

That's what I have been doing. Moving work to a background thread with RxJava, measuring how long methods take to run using Hugo and caching everything. I have been a bit obsessed with it for the past days and saw a lot of improvements but I still see some frames dropped here and there.

For example, when you start a new activity/replace a fragment from the drawer, the animation of it closing drop frames in pretty much every app, even on Google made apps.

2
MindInMotionMkd•

On google apps, go to IO app here they are postponing switching to other navigation item until the drawer retracts.

Basically, they just guessed the delayed time for the drawer to become STATE_IDLE.

6
numrosOP•

I have seen this solution on StackOverFlow before and I don't like it. It reduces app responsiveness and just shows how messed up the threading architecture is. I have used artificial delays to avoid animations from lagging but every time I do it a part of me die.

9
cyrilpillai•

Artificial delay seems a super hacky way to do it. I achieved it by adding a listener to the drawerLayout. Checkout the code

5
MindInMotionMkd•

No need of threading, handler would work scheduling delayed message or just wait for drawer state to change to IDLE and execute the fragment transaction or activity.

2
mioimao•

Gpu overdraw? Check the depth on your layouts.

1
will_r3ddit_4_foodNougaty Goodness•

Good information

1
sungawd•

Android caters to many different types of phones. An app on Android checks the phones dimensions and other things dealing with UI resizing that iOS just does not need to.

9
Dr_funny_guy•

There is just 1 simple reason. On Android there is no guarantee to have a consistent delta time from 1 frame to another. This is because the garbage collector can go off at anytime. On iOS this guarantee doesn't exist too but it is deterministic, you can predict how much GC autoreleasepools will do and you can write your animation loops accordingly. That's it, all other "reasons" do contribute to jitter on android, but this is the core.

5
leggo_tech•

shit seems fluid on my pixel.

1†
rosshambrick•

I know you're getting down voted, but there's truth in this.

Google put a lot of effort into optimizing the latency in the Pixel since they now have full vertical control over the hardware and software.

I've used a lot of iPhones and Android phones over the years and the Pixel is the only one that feels as smooth as an iPhone. I'm impressed every day that I use it.

12
leggo_tech•

it was a low effort shit post. figured id get downvoted. Basically just saying that if they actually had a dedicated team and hardware they can pull it off. I don't think this had to wait till 2016 to happen. I just think it finally hit them. the new hardware guy at google is doing a great job. this has been because of him. imo.

2
jack_underwood1Today Calendar Dev•

It's possible to produce 60fps apps, it just takes a lot more effort on Android than it does on iOS.

-1
y2k2r2d2•

Java anybody?

-3
Rhed0xRX is overrated•

No, ART is really fast.

3
y2k2r2d2•

I see games and other native CPp UIs made, those are very fast.

0