Hey Flutter devs! I’m excited to announce the release of Hive CE v2.11.0-pre, introducing a new interface called IsolatedHive—a safe way to use Hive across multiple isolates.
What’s New:
- IsolatedHive Interface: Enables safe Hive usage across isolates by maintaining its own dedicated isolate for database operations. It utilizes an
IsolateNameServer
behind the scenes to locate the Hive isolate. - Flutter Integration: Simply call
IsolatedHive.initFlutter
fromhive_ce_flutter
to automatically set things up to use Flutter’s built-inIsolateNameServer
. - Generated Extensions: The latest
hive_ce_generator
now provides the same easy-to-useregisterAdapters
extension onIsolatedHive
.
Why Use IsolatedHive?
You might already be using isolates without realizing it! Common Flutter scenarios benefiting from isolate-safe Hive:
- Desktop apps with multiple windows
- Background task handling (
flutter_workmanager
,background_fetch
, etc.) - Push notification processing
Note: Hive now prominently warns you if it detects unsafe isolate usage.
🎥 Multi-window Demo:
Video: https://files.catbox.moe/stb5gs.mov
Repo: https://github.com/Rexios80/hive_ce_multiwindow
Performance Considerations:
While IsolatedHive
adds overhead due to isolate communication and isn’t quite as fast as regular Hive CE, it’s significantly faster and leaner than Hive v4:
Operations | Hive CE Time | IsolatedHive Time | Hive CE Size | Hive v4 Time | Hive v4 Size |
---|---|---|---|---|---|
10 | 0.00 s | 0.00 s | 0.00 MB | 0.00 s | 1.00 MB |
100 | 0.00 s | 0.01 s | 0.01 MB | 0.01 s | 1.00 MB |
1000 | 0.02 s | 0.03 s | 0.11 MB | 0.06 s | 1.00 MB |
10000 | 0.13 s | 0.25 s | 1.10 MB | 0.64 s | 5.00 MB |
100000 | 1.40 s | 2.64 s | 10.97 MB | 7.26 s | 30.00 MB |
1000000 | 19.94 s | 41.50 s | 109.67 MB | 84.87 s | 290.00 MB |
Stability & Testing:
This pre-release is as stable as possible without real-world external testing—your feedback is invaluable!
Check it out, give it a spin, and share your experience:
Happy coding! 🐝✨