fast_blurhash 是一個高效率的 Dart FFI 套件,透過使用 Rust 進行高效運算,加速 BlurHash 解碼。它能快速產生與呈現低解析度的佔位圖像,非常適合提升影像載入工作流程中的感知效能。透過將密集型運算交由原生 Rust 程式碼處理,相比純 Dart 實作,大幅降低 CPU 開銷。此套件支援 Android、iOS、macOS、Windows 與 Linux 多個平台,適用於需要在影像載入期間提供順暢視覺回饋的跨平台應用。
適用情境
快速圖像佔位符渲染
改進的應用感知效能
高效加載遠端圖像
即時預覽產生
背景圖像處理
跨平台相容性
主要特色
基於 Rust 的高效能
Dart FFI 結合
多平台支援
低記憶體佔用
高速解碼
無縫的 Flutter 結合
適合對象
載入大量圖片的應用
性能關鍵的UI
圖像密集型儀表板
使用佔位符進行原型設計
尋求原生速度的開發者
使用建議
本地建構需要 Rust 工具鏈
僅限 BlurHash 解碼(不包含編碼)
平台特定的原生依賴
CI/CD上的潛在構建複雜性
可能會稍微增加應用二進制檔案大小
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
fast_blurhash
A Dart FFI package project that uses Rust to decode the blurhash and encode the final image, utilizing FFI to call these functions. This package exists because it works +20x faster on average than the common Dart implementation and can be tested in release mode by running the benchmarks.dart demo.
It only works with the latest version of Flutter on the main branch and requires the following feature to be enabled: flutter config --enable-native-assets. For more details, refer to this issue.
Status
Uses experimental APIs which might change in the future.
The first time call takes longer than the average time so I have added a setup function to do a warmup call.
Tested only on iOS and MacOs in release mode.
Significant performance difference between release mode and debug mode; do not rely on debug mode results.
Project structure
This template uses the following structure:
rust: Contains the rust source code.
lib: Contains the Dart code that defines the API of the plugin, and which calls into the native code using dart:ffi.
Benchmarks
To test the performance of the package in release mode, run the benchmarks.dart demo.
So far I have tried this one iOS and macos release mode, don't run the benchmarks on debug mode.
Run the benchmark using : flutter run -t lib/benchmarks.dart --release