3 line optimisation in Habitica
I'm using a RPG TODO list that gets me going. Unfortunately, the project was a little bit slow when scrolling through my big list. Lucky for me, the project is open source so I was able to track the problem down and fix it myself.
There were many parts of the application that could've done this.. So I had to pull stuff out and see if everything is still slow.
Finally, I've found the error. Instead of showing text with TextView, Habitica is using a emoji library to display it. So instead of displaying the unicode for a smile, it actually replaces it with a bitmap image. I initially the lag on my phone came from the RecyclerView – because the bottleneck was when creating each of the sub views (for each task), but it turned out to be the rendering of the emojis. For each character in the text it would go through a huge decision making, even when no emojis were present in the text. For each letter it took about 1ms. So for a text such as "Daily – 10" it would have around 10ms delay. You can see the changes I've made here.
I'm surprised that it was such an easy fix.