bloc icon indicating copy to clipboard operation
bloc copied to clipboard

feat(hydrated_bloc): Isar instead of Hive for storage

Open ac130kz opened this issue 4 years ago β€’ 28 comments

Description

Hive has an issue with high RAM usage, no support for queries and less than desirable performance for complex data [1], which in my opinion fits the purpose of hydrated_bloc. Recently a complementing library to solve these issues from the same author (@leisim) got released into stable, and it's called Isar [2]. For now, it comes with two primary downsides: it is still quite young, the web support is to (soonβ„’).

Desired Solution

Hive is replaced with Isar as the main means of dealing with cached storage within hydrated_bloc.

Alternatives Considered

Hive alternative Objectbox [3] is not written in Rust (unlike Isar), thus any memory, undefined behaviour and concurrency related bugs will be present in higher amounts and will be harder to spot even for experts since it's inherently harder to setup for safe reliable code. However, it comes with a variety of interfaces to other languages, e.g. Kotlin and Swift.

Additional Context

[1] https://github.com/hivedb/hive/issues/246 [2] https://github.com/isar/isar [3] https://github.com/objectbox/objectbox-dart

ac130kz avatar Jan 01 '22 17:01 ac130kz

Hi @ac130kz πŸ‘‹ Thanks for opening an issue!

I'll take a closer look at Isar now that it's stable to evaluate if it makes sense to make this transition.

My initial reaction is to compare performance between Hive and Isar (are you aware of any official benchmarks?) and to create a small p.o.c.

My main concern is it looks like Isar doesn't support web whereas Hive does. Also, Isar relies on code generation so hydrated_bloc would likely also require developers to run build_runner which is a disadvantage when compared to Hive in my opinion.

I'll drop some more thoughts/comments once I've taken a closer look at Isar and the level of effort to migrate to it but feel free to add your thoughts in the meantime, thanks! πŸ™

felangel avatar Jan 01 '22 17:01 felangel

@felangel I guess as a temporary performance measurement Objectbox's benchmarking suite can be updated to support the latest version of Isar [1]. As for the build_runner, I think it might not be such an issue, fingers crossed static metaprogramming in Dart will help in this regard within a couple of months [2].

UPD: found a mention of preliminary benchmarks by @leisim on Reddit [3].

[1] https://github.com/objectbox/objectbox-dart-performance [2] https://github.com/dart-lang/language/issues/1482 [3] https://www.reddit.com/r/FlutterDev/comments/rti7sk/stable_version_of_isar_database/hqt6geg/

ac130kz avatar Jan 02 '22 07:01 ac130kz

@felangel I guess as a temporary performance measurement Objectbox's benchmarking suite can be updated to support the latest version of Isar [1]. As for the build_runner, I think it might not be such an issue, fingers crossed static metaprogramming in Dart will help in this regard within a couple of months [2].

UPD: found a mention of preliminary benchmarks by @leisim on Reddit [3].

[1] https://github.com/objectbox/objectbox-dart-performance [2] dart-lang/language#1482 [3] https://www.reddit.com/r/FlutterDev/comments/rti7sk/stable_version_of_isar_database/hqt6geg/

That still doesn't address the lack of web support and I agree that static metaprogramming will likely help with codegen; however, it feels premature to make this change given the current state of things. I think it'd be nice to revisit this in a few months.

felangel avatar Jan 10 '22 04:01 felangel

Isar now supports Web https://pub.dev/packages/isar/changelog#220 but I also think it's still too early πŸ˜›

PawlikMichal25 avatar Feb 24 '22 12:02 PawlikMichal25

Is there any news about this thread?

cofirazak avatar Aug 18 '22 10:08 cofirazak

Isar FAQ:

Isar vs Hive

The answer is easy: Isar was started as a replacement for Hive and is now at a state where I recommend always using Isar over Hive.

anlumo avatar Nov 06 '22 17:11 anlumo

Isar FAQ:

Isar vs Hive

The answer is easy: Isar was started as a replacement for Hive and is now at a state where I recommend always using Isar over Hive.

Which contridicts with

image

(src https://github.com/hivedb/hive/issues/246#issuecomment-997182092)

maximveksler avatar Nov 07 '22 06:11 maximveksler

Where you start and where you end up are not always the same place !

Gene-Dana avatar Nov 07 '22 12:11 Gene-Dana

Isar, having it's core implemented in Rust needs to bundle a priori a non dart binary.

This makes the whole dependency chain much more complex, which may fit heavy lifting cases however I would aruge does not fit the general purpose library use case of bloc.

IMHO switching would be a bad call.

As an alternative, either staying with Hive or using shared_preferences seem like viable options.

maximveksler avatar Nov 07 '22 14:11 maximveksler

needs to bundle a priori a non dart binary

Given the size of Flutter libs alone, it is not an issue.

using shared_preferences

It's not a performance oriented approach, while Hive itself is barely maintained.

I believe it's the time to move with isar or SQLite via drift.

ac130kz avatar Nov 07 '22 15:11 ac130kz

What about removing all storage implementations from hydrated_bloc itself and just offering different options as separate packages?

I don't think that there is a one-size-fits-all approach to this.

anlumo avatar Nov 07 '22 15:11 anlumo

What about removing all storage implementations from hydrated_bloc itself and just offering different options as separate packages?

I don't think that there is a one-size-fits-all approach to this.

How would that be an improvement over the current version? You can already create your own custom storage implementation and we'd likely still want a default implementation that is generally a good fit for the most common use-cases.

felangel avatar Nov 07 '22 15:11 felangel

My worry is that I don't want to ship the full hive package just for hydrated_bloc. However, maybe I'm just victim to my ignorance whether the tree shaking algorithm is good enough to get rid of it if I use my own custom storage implementation instead.

anlumo avatar Nov 07 '22 15:11 anlumo

My worry is that I don't want to ship the full hive package just for hydrated_bloc. However, maybe I'm just victim to my ignorance whether the tree shaking algorithm is good enough to get rid of it if I use my own custom storage implementation instead.

I believe tree-shaking should take care of it but feel free to open a separate issue if that's inconsistent with what you're observing.

felangel avatar Nov 07 '22 16:11 felangel

s there any news about this thread?

devappbox avatar Mar 26 '23 04:03 devappbox

Is there any update on this?

Otherwise, I'll try something. I'm diving deep into this storage rabbit hole.

amanxnanda avatar Mar 27 '24 09:03 amanxnanda