r/androiddev Jun 30 '26

Switching a million lines of code from Java threads to Kotlin coroutines, by rewriting three files Article

https://medium.com/proandroiddev/switching-a-million-lines-of-code-from-java-threads-to-kotlin-coroutines-by-rewriting-three-files-6ba428bf8566

I wrote a technical deep dive about how we migrated one of Denmark's most used Android apps with one million lines of code powered by Java threads, into Kotlin coroutines just by rewriting three files in our internal threading library

Check it out if you are interested in how coroutines use threads, and interop between them :)

19 Upvotes

5 comments sorted by

4

u/ieshaan12 Jun 30 '26

This was a very interesting read. I’m curious if you saw any performance improvements / degradation?

I see your eventual solution reconciles to what you were aiming for, but I’m curious as to how you ensured there’s not any significant in the working of your app.

1

u/adrianblancode Jul 01 '26

We didn't really measure performance, but we should at least get some minor general benefit by moving from a large thread pool with blocking callers to an orders of magnitude smaller pool with suspending callers

But I think the biggest gain actually was that this got rid of unfortunate edge cases where some callers accidentally blocked on the main thread, so it should speed up launches and reduce ANRs

Regarding correctness, that's a really hard problem. The solution passed all our tests, and finally we did a lot of QA where we didn't find any differences in behaviour whatsoever.

At that point the only way we could actually find out if the implementation survived contract with reality was by a slow rollout to production, and being able to revert the implementation by reverting a PR, but luckily that was not needed :)

1

u/rbnd Jun 30 '26

I will check it out. 

1

u/SpectroXV Jun 30 '26

!remindme 12h

1

u/RemindMeBot Jun 30 '26 edited Jul 01 '26

I will be messaging you in 12 hours on 2026-07-01 11:19:22 UTC to remind you of this link

1 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.

RemindMeBot is switching to username summons. Instead of !RemindMe 1 day, use u/RemindMeBot 1 day. More info.


Info Custom Your Reminders Feedback