@marcinmoskala.bsky.social

To optimise, you must measure. To choose the right approach for performance measurement, you must answer the most important question: What do you want to measure?

Bild

Which one really scales better for high-concurrency workloads? 🤔 Are there reliable benchmarks comparing coroutine performance with Loom’s virtual threads?

Bild

Most people do not even think about cancellation, but it is extremely important, and both Android and backend developers benefit from Kotlin Coroutines cancellation mechanisms. Let me give you some examples.

Bild

Coroutines are incredibly powerful, but their hidden complexities can trip up even experienced developers. While this topic is not new, my recent webinar on "Mistakes You Make Using Kotlin Coroutines" was packed — and for good reason!

Bild

What are the advantages of Kotlin over Java TODAY? Since Kotlin gained popularity, Java has started dynamically introducing features inspired by Kotlin. But what does Kotlin still have up its sleeve, and is it reachable for Java? Here is the list of the most important advantages:

Bild

Where should I keep me state in Compose? In component, view model, data layer or outside? This question can be reformulated as: How long do you want it to exist?

Bild

Kotlin Coroutines provide special support to interoperate with Java, Swift and JavaScript. Thanks to that, calling suspending functions is a breeze.

Bild

Many devs start using technology without understanding it first. That is fine, but some technologies give fake confidence, and devs misuse it without even realizing it. Let me use Kotlin Coroutines as a case study. Thread 👇🧵

Bild

Testability is one of the most important advantages of Kotlin Coroutines. It supports operating in virtual time, which lets us write precise, fast, and deterministic tests for cases that are hard to test with other libraries. You can easily check any scenario and assert how much time it would take.

Bild

VOTING 👇 What’s the #1 reason developers avoid or struggle with Kotlin Coroutines? 1️⃣ Seems too complex 2️⃣ Legacy code (RxJava) 3️⃣ Unclear best practices 4️⃣ Don’t know where to start Vote and share your experience in the comments, I’m really curious to hear your stories!

Bild

Dispatchers.Default and Dispatchers. IO share the same pool of threads, but each has its own independent limit. The pool is unlimited, and threads are created as needed.

Never make blocking operations on suspending functions without appropriate dispatcher! Most coroutines run on a small pool of threads (Main in Android, Default on backend), and blocking can easily cause thread starvation. The simplest way to fix that is using IO dispatcher, there are better options:

Bild

To turn a function into a flow that emits its result, you can just use flow builder with emit. Many projects define a function for that. You can also turn a lambda function using asFlow.

Bild