Reduce Android Lag

Syphonx

Expert Member
Joined
Jun 25, 2008
Messages
4,344
Reaction score
899
Location
Cape Town
http://forum.xda-developers.com/showthread.php?t=1987032

Hey everyone,

So, I was experiencing significant lag as we all do from time to time, and decided I was going to get to the bottom of it.

After tracing and debugging for hours, I discovered the source of 90% of Android's lag. In a word, entropy (or lack thereof).

Google's JVM, like Sun's, reads from /dev/random. For all random data. Yes, the /dev/random that uses a very limited entropy pool.

Random data is used for all kinds of stuff.. UUID generation, session keys, SSL.. when we run out of entropy, the process blocks. That manifests itself as lag. The process cannot continue until the kernel generates more high quality random data.

So, I cross-compiled rngd, and used it to feed /dev/urandom into /dev/random at 1 second intervals.

Result? I have never used an Android device this fast.

It is literally five times faster in many cases. Chrome, maps, and other heavy applications load in about 1/2 a second, and map tiles populate as fast as I can scroll. Task switching is instantaneous. You know how sometimes when you hit the home button, it takes 5-10 seconds for the home screen to repopulate? Yeah. Blocking on read of /dev/random. Problem solved. But don't take my word for it .. give it a shot!

Update!
I've built a very simple Android app that bundles the binary, and starts/stops the service (on boot if selected). I'll be adding more instrumentation, but for now, give it a shot! This APK does not modify /system in any way, so should be perfectly safe.

This is my first userspace Android app, so bear with me!

Note that this APK is actually compatible with all Android versions, and all (armel) devices. It's not at all specific to the Captivate Glide.

Caveats
There is a (theoretical) security risk, in that seeding /dev/random with /dev/urandom decreases the quality of the random data. In practice, the odds of this being cryptographically exploited are far lower than the odds of someone attacking the OS itself (a much simpler challenge).
This may adversely affect battery life, since it wakes every second. It does not hold a wakelock, so it shouldn't have a big impact, but let me know if you think it's causing problems. I can add a blocking read to the code so that it only executes while the screen is on. On the other hand, many of us attribute lag to lacking CPU power. Since this hack eliminates almost all lag, there is less of a need to overclock, potentially reducing battery consumption.

If you try it, let me know how it goes.

ROM builders - feel free to integrate this into your ROMs (either the .apk / application, or just the rngd binary called from init.d)!

If anyone's interested, I've launched a paid app on the Play store for non-xda users. As I add features I'll post the new versions here as a thanks to you guys (and xda community at large for being such a great resource). But if anyone's interested in the market's auto-update feature, just thought I'd mention it.
Looks interesting, haven't tried it yet but post back here if you do and notice a difference
 
I am running this and ram manager set to balance with 256mb swap file , must say my htc one v feels much faster , then it was before
 
Installed on my S3 after reading the positive comments on XDA and it works incredibly well. No more lag at all. Really impressed...
 
I do think we have a winner.

Can not say if its my imagination or wishful thinking but it does seem to work.
 
Yes, it does seem to work on my SGS, which I was getting frustrated with after increasing lag. Its early days yet, but pleasant to see it working immediately on installing.
 
Very exciting news! I'll give it a try on my slowish and ageing Motorola Defy and give feedback. I hope Google will eventually just fix this issue themselves..
 
Holy ****. Tried this on my old Galaxy Tab P1010 and it works. Its never been this fast, even straight out of the box :-/
 
I installed the app, can't tell the difference. S3.
 
Installed on S2 yesterday, can't notice a diff, possibly worse... benchmark score dropped a little as well.
 
It would appear this has a better effect on older phones and is negligible on the newer power houses (S3/Note 2).
 
It would appear this has a better effect on older phones and is negligible on the newer power houses (S3/Note 2).

Looks like it.

My Xperia is smooth as silk with a single pause once in a while instead of the constant jitter, but no change on my TF101
 
I noticed a difference on my S2 and Nexus 7 although on the Nexus 7 I found the wallpaper scrolling to be a bit iffy
 
So far my phone feels good, it's hard to quantify if it's better but there isn't really any lag happening now. So perhaps it does work?
 
Top
Sign up to the MyBroadband newsletter
X