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
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.
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.
Right you are - I'd forgotten about that. Good addition!
ART is not the issue, it's pretty damn fast.
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.
The GC is part of ART and they spent a lot of time optimizing it.
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.