4
0

Hive CE 2.11.0-pre: Introducing IsolatedHive for Safe Multi-Isolate Usage!

1y 2mon ago by lemm.ee/u/Rexios in flutter@programming.dev

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 from hive_ce_flutter to automatically set things up to use Flutter's built-in IsolateNameServer.
  • Generated Extensions: The latest hive_ce_generator now provides the same easy-to-use registerAdapters extension on IsolatedHive.

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:

OperationsHive CE TimeIsolatedHive TimeHive CE SizeHive v4 TimeHive v4 Size
100.00 s0.00 s0.00 MB0.00 s1.00 MB
1000.00 s0.01 s0.01 MB0.01 s1.00 MB
10000.02 s0.03 s0.11 MB0.06 s1.00 MB
100000.13 s0.25 s1.10 MB0.64 s5.00 MB
1000001.40 s2.64 s10.97 MB7.26 s30.00 MB
100000019.94 s41.50 s109.67 MB84.87 s290.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! 🐝✨