How We Made Android 3x Faster
This was a side project we were working on. It’s not finished but it’s a good proof of concept. We hope the Android’s team picks it up and deploys it.
The video belows demoes what we built.
Results
x3 speed up of Android UI
a lot less ANR
Our code with the Android patch and our demo app is on Github.
How Did We Do It?
Android's UI is single threaded. The app crashes if you try to update the UI from another thread. We removed this limitation, and added a few lines of codes to make it all work (shameless ad: we found these lines through our analysis tools).
The main problem we resolved was that the View class updates blocks redraw events because they’re all executed on one thread. E.g. 50 instructions are executed on Views and one redraw. The instructions to execute gets overloaded resulting in thrashing which creates ANR. We added a few simple synchronization primitives to allow the two updates to happen at the same time.
A “real world implementation” would have used better concurrency methods and avoided inconsistent updates… But still this works pretty well for a few hours of work and it seems
Next Steps
It’s a side project we made to test our product. We publish it because we believe it is useful to the Android ecosystem. As soon as we have enough free time, we’ll make the View class completely thread safe and push it to the Android project unless someone picks it up and fixes it in the meantime.
In general, the Android codebase is riddled with these kinds of problems. Because it’s our job at Manycore to detect and resolve these problems automatically, we’ll find more of these problems and we’ll do our best to fix them for Android.
We love Android and it deserves the best. We want to make it better.