DartConcurrencyPerformance

Dart Isolates: The Missing Guide for Production Flutter Apps

2024-08-12 · 8 min read · by Ishaq Hassan

Concurrency primitives, ports, real-world patterns. The piece every Flutter dev wishes they had read before shipping their first heavy compute feature.

Read on

Read on Medium โ†’

Key takeaways

Frequently asked questions

When should I use an isolate vs async/await?

Use async/await for I/O-bound work like network calls and file reads. Use an isolate when CPU-bound work would block the UI thread, typically anything over 16ms of synchronous compute on the main isolate.

What is the overhead of spawning an isolate?

Around 1-3ms on modern devices, plus the memory cost of a fresh heap. For one-shot work, compute() amortises this nicely. For repeated work, keep an isolate alive and message it.

Can isolates share memory?

Not in the general case. They communicate via copied messages. TransferableTypedData and Isolate.exit can move ownership of typed buffers without a copy, which is the main exception.

Why does my isolate code freeze the UI?

Most likely you are awaiting the isolate result on the main isolate without a yield. Wrap the call so the main isolate stays responsive while the worker runs.