Performance issue in Chucker

As an Android Engineer, I love using Chucker for intercepting network requests and debugging issues. And it is a great achievement for me to be a part of the contributors of this library.

It all started with a bug we experienced with my co-worker. In our project, we have a specific screen for capturing an image of a person. After capturing the image, we send the image as a base64 string to the backend. Sometimes, we have issues with this API, and we used to investigate what went wrong by looking at the request in Chucker.

Unfortunately, when we tried to check the request with a base64 body payload, we had to wait a couple of minutes. It might even crash on low-memory devices.

I was so curious about how to fix this issue and what was behind it. So, I forked the project Chucker from GitHub and opened it in my IDE. Then I started exploring the code where the requests are presented in the UI.

Finally, I found the issue. The request payload string was being split into lines and was given to RecyclerView to be presented. RecyclerView is a specific UI element that is used to represent lists. In this way, the UI does not freeze for long strings, because the string is not presented at once — only lines that fit the screen height will be presented.

The JSON is split into lines by checking specific line break characters like '\n'. The problem with base64 is that it does not contain any line breaks. So, a single item in the UI can be very large and can cause the UI to freeze. To solve this issue, I changed the logic for splitting the string into lines. After getting every line, I checked whether the line exceeds a certain threshold. If it exceeds, I break the line itself into sublines to avoid UI freeze.

I created a new branch in the forked repo. I created a new network request with a large base64 payload in the sample app, then I recorded the issue, applied a fix, and recorded again. I created a PR, and after a while, it was merged to the main codebase.

If you want to check more about details, you can use this url to my PR.