Despite some truly top notch hardware, some high end Android devices still seem to have trouble with some games. I had experienced some lagginess with games and often put it down to the processor or chipset. Over on XDA forums, lambgx02 had originally posted the Seeder Entropy Generator to stop lag on various Android devices. The running premise was that most game lag was caused by entropy.
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.
The result of fixing this issue is that games run much, much smoother.
An “entropy pool” can be considered to be a set of random bits. It could be used for generation of objects, for data encryption, randomisation etc. Many Android tasks run much slower than they should for one simple, but not-so-obvious reason: they read random data from a limited “blocking” random device. Random data is used to generate session keys and UUIDs, in SSL, and frequently during inter-process communication. This data (entropy) runs out frequently, and that causes any process reading from the blocking device to stop responding (lag). These processes cannot continue until the Linux kernel repopulates the entropy pool, which takes time.
Another user bradman117 tested and confirmed that it worked for the Nexus 7. So far, users on other devices such as the Optimus 2x, SGS3, have have reported excellent results though you would need a rooted system. Installation is easy as well, it’s a simple zip to flash in recovery. Alternatively, there’s a very simple Android app that bundles the binary, and starts/stops the service (on boot if selected). Give it a try on your Android device and you may see performance improve! This APK does not modify /system in any way, and is very safe. I have tried it on my Nexus 7 and not sure if it’s a placebo effect, overall it does seem faster.
Update: It’s been confirmed that the speed up was largely due to the CPU processor being kept awake and constantly running at max performance. Hence, the impression of improving lag response. This would just drain battery and not an ideal way to speed up the system. Download link removed.
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). Next, yhis may adversely affect battery life, since it wakes every second.