Overcoming the fear of profiler — Say Hello to Optimisations? Part I

Asheesh Sharma
6 min readOct 15, 2022

--

DisclaimerThis is not a technical blog and does not include code snippets, an event of life that helped me, my team understand the importance of profiling so we all can get inspired and start working on it :)

Part I- Storytelling about why understanding to profile in depth is important?
Part II-
Positively Enforcing the habit of profiling within Team for the greater good. Tomorrow, 05:00 PM IST 🎉 🎊
Part III- Unraveling the mystery of 0ms view creation time, DO NOT MISS IT :)

I always feel there is always a scope for optimization be it design, code, or life.

Recently(~1.5 years back), I was on a mission to optimize the Zomato app and realized that there were a lot of areas where I could get my hands dirty, so I decided to put insomnia to better use.

I could feel the fire in my fingers, waiting for the moment to get started. Being confident about the code, I was feeling no less than a mad scientist who ends up discovering the tip of the iceberg and considers it as the real deal.

Since using a profiler is always considered a non-trivial task, I was trying everything possible to convince myself that I can figure out the black zones better than the profiler :).

Feeling accomplished after not using the profiler and with no concrete proof that I had done any sort of optimization, I decided to share it with the senior tech folks, thinking that I had finally reached the North star, I shared it with him, and his first question was — Tell me the numbers and I was all blank, I countered with statements that it feels smooth even to the whole team but He said — Numbers reveal the truth always and I knew he was saying right but I closed the call saying that I will get back on this and he knew I had been running away from proper profiling.

And I was confused and I did not have any numbers and had no prior deep experience around profiling code, a fear I had been avoiding facing and trying to fight over with the shield of code context and knowledge. I clearly remember the date, it was the day before republic day and the meeting happened around 09:00 PM, well I was disappointed and more broken than I was around my last heartbreak. 🙃

I asked several teammates again about the same and they all said yes it feels a lot better now but still no numbers, around 11:00 PM I decided to go ahead with profiling, after all, it’s all code, and I should be able to crack it.

I started going through various sites, and videos trying to figure out the art of profiling, but again I was not able to connect with it directly maybe it was my google search skills(which I doubt :P) or lack of concrete resources around profiling.

After spending hours, trying to grab as much as I could I decided to put everything I have learned to use. I knew the easiest way to optimize scroll was to profile the views creation and the operations being done in onBind, fair enough. (Decided to start with scroll optimization over app startup optimization)

A profiler is the easiest way to figure out the issues in the code. Once you have overcome your fear of not using it, it’s no less than a panacea for optimizations. 💻 📈

The time I scrolled and saw the profiler analysis, I was in a deep shock, even the simpleton atomic components were taking a crazy amount of time to render and the time every onBind was taking for complex views was beyond my imagination, I knew my code and I always had been confident that my team had written it in the most optimized fashion, we do have committed sins knowingly but never in my wildest imagination I could imagine that it could contribute in producing an unoptimized performance to this extent, well I started going deeper(in embarrassment) and the more I was going in, the feeling that I had been an unoptimized programmer kept growing. 😓

Well after an hour or so, I had a fair number of points to help my scroll friend feel better, and a few hours before sunrise. Game on is what I said to myself and started working on them, as I was profiling in parallel, I could see amazing results which were acting no less than Java chip Frappe(My goto drink) to me to keep me awake.

I kept working and fixing all I could find(How I found out what to fix in Part II) but I still felt that I was not getting the thrill, it was getting boring after I reduced the major obvious junk and figured out what can bring a massive improvement app-wide and if fixed, it will be a crazy improvement.

So I decided to move to the next phase, which was optimizing app start, just to set the right preface, I did some optimizations before there too but I had no numbers so the first thing I did was go to the old code, profile, switch to new code, and profile again, well the actual numbers were nothing compared to what I thought it should have been.

Disappointed, I started profiling and found a jackpot in the first 60seconds, An operation being done on the main thread which was taking around 600ms, well luck it was, I knew what the code was doing, well what all was left was a play of threads, and boom, saved ~600ms and I kept laughing for a minute or so thinking this might be the reason why was I being pushed to get the real numbers.

I was able to see what macro improvements could be found and done without much pain and the code I could have never found with bare eyes.

Macro vs micro — It was a fantastic improvement and learning for us. 🎖️

Well, self-learning is great but you are only called a good leader if only you can transfer the knowledge to your team and they are also able to use it and I wanted them to learn this art badly for their own growth. :)

Part II — Wait for tomorrow for the second part, I will share how I positively enforced it within the team :)

If you learned something new from this post, don’t forget to hit the 👏 icon. Stay tuned for the next one!

Always up for discussing anything cool, feel free to connect.
LinkedIn: Asheesh Sharma
Twitter: Dev_Asheesh

--

--