Flutter Too Slow for Images? Rush It With Rust
Article Summary
Amorn Apichattanakul from KBTG just shattered a common Flutter myth: it's not the language that's slow, it's the codec. His benchmark results are eye-opening.
A Google Developer Expert for Flutter tested image processing performance across six different approaches: pure Dart, Kotlin via MethodChannel, and Rust via FFI. The results challenge everything developers assume about Flutter performance bottlenecks and bridge overhead.
Key Takeaways
- Pure Dart took 5009ms for image processing vs 128ms with optimized Rust
- MethodChannel actually beat basic Rust FFI (132ms vs 226ms) due to codec differences
- Bridge copy overhead was only milliseconds, not the performance killer everyone assumes
- Swapping two Rust libraries dropped processing time from 205ms to 142ms
- flutter_rust_bridge auto-compiles Rust during Flutter build, adding only 0.8MB to APK
The performance gap between Dart and native isn't about the language or FFI overhead, it's about which codec library you're using and whether it leverages SIMD instructions.
About This Article
Amorn Apichattanakul found that isolates, which are commonly used to prevent UI freezing in Flutter image processing, actually made things slower. The isolate version ran 2x slower at 5009ms compared to 2957ms, and it used 127MB extra memory because of data copying to background efficiency cores.
He integrated Rust into Flutter using flutter_rust_bridge, which auto-generates FFI glue code and compiles Rust during the normal Flutter build process. This eliminated the need to manually manage .so files or write platform-specific code in Kotlin and Swift.
By switching to optimized Rust libraries like zune-jpeg, fast_image_resize, and jpeg-encoder, processing time dropped from 205ms to 142ms. That's only 10ms slower than native Kotlin, and it added just 0.8MB to the APK size.