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