Zhuinden / realm-monarchy

[ACTIVE-ISH] A wrapper over Realm which exposes it as LiveData, managing Realm lifecycle internally.
Apache License 2.0
88 stars 11 forks source link

Support emission of frozen results #32

Closed Zhuinden closed 4 years ago

Zhuinden commented 4 years ago

With Realm-Java 7.0.0, now it's possible to expose frozen results instead of copied results from the background looper thread.

On the other hand, even though it's simple, I don't feel like writing the code.

If anyone actually wants it, I might.

ganfra commented 4 years ago

I might be looking for this, but I have lots of issues on 7.0.0 compared to 6.1.0...

Zhuinden commented 4 years ago

@ganfra what kind of issues?

ganfra commented 4 years ago

Mostly crashes

Zhuinden commented 4 years ago

@ganfra anything specific, or native crashes? :confused:

ganfra commented 4 years ago

Both :D

Zhuinden commented 4 years ago

How many objects are you trying to show from Realm between the threads?

If it's over 10000 objects then I'll write the code... today or tomorrow.

Although I sincerely doubt it'll help with the native crashes. Seriously, Core 10 just doesn't come fast enough.

ganfra commented 4 years ago

Yes I do not ask that for fixing crashes, waiting for realm to release something not buggy... Anyway, transactions and reading are getting so slow when having lots of objects in db (more than 75000) and lots of listeners, a bit disappointed by this.

Zhuinden commented 4 years ago

75000? yeah, I'll figure this out, then. You are looking for frozen results.

This library hasn't been updated in 1.5 years and is still using android.arch.* and support lib v27?

Ugh... :sweat_smile: Anyway, you'll see when it's updated.

ganfra commented 4 years ago

Actually I'm not retrieving 75000 directly, I was just pointing that realm is getting slow when the database is growing a lot, no regard with Monarchy :) But yes, if you have time to make some updates, I'll appreciate!

Zhuinden commented 4 years ago

Initial AndroidX migration is done: https://github.com/Zhuinden/realm-monarchy/commit/0ad10fa5703439982c65318f80397aed6ece7fc4

Frozen Results support will come in next commit if all goes well.

Zhuinden commented 4 years ago
06-25 20:31:41.216 4805-4844/? A/art: art/runtime/runtime.cc:366] Pending exception java.lang.UnsupportedOperationException: 'freeze()' is not supported by OrderedRealmCollectionSnapshot. Call 'freeze()' on the original 'RealmCollection' instead.
06-25 20:31:41.216 4805-4844/? A/art: art/runtime/runtime.cc:366]   at java.lang.UnsupportedOperationException io.realm.OrderedRealmCollectionSnapshot.getUnsupportedException(java.lang.String) (OrderedRealmCollectionSnapshot.java:133)
06-25 20:31:41.216 4805-4844/? A/art: art/runtime/runtime.cc:366]   at io.realm.OrderedRealmCollection io.realm.OrderedRealmCollectionSnapshot.freeze() (OrderedRealmCollectionSnapshot.java:168)
06-25 20:31:41.217 4805-4844/? A/art: art/runtime/runtime.cc:366]   at io.realm.RealmCollection io.realm.OrderedRealmCollectionSnapshot.freeze() (OrderedRealmCollectionSnapshot.java:51)
06-25 20:31:41.217 4805-4844/? A/art: art/runtime/runtime.cc:366]   at void com.zhuinden.monarchy.FrozenLiveResults.updateResults(io.realm.OrderedRealmCollection) (FrozenLiveResults.java:47)
06-25 20:31:41.217 4805-4844/? A/art: art/runtime/runtime.cc:366]   at void com.zhuinden.monarchy.Monarchy$3.onChange(io.realm.RealmResults) (Monarchy.java:202)
06-25 20:31:41.217 4805-4844/? A/art: art/runtime/runtime.cc:366]   at void com.zhuinden.monarchy.Monarchy$3.onChange(java.lang.Object) (Monarchy.java:199)
06-25 20:31:41.217 4805-4844/? A/art: art/runtime/runtime.cc:366]   at void io.realm.internal.ObservableCollection$RealmChangeListenerWrapper.onChange(java.lang.Object, io.realm.OrderedCollectionChangeSet) (ObservableCollection.java:39)

How cute. :smirk:

Zhuinden commented 4 years ago

Released in 0.7.1.

Theoretically Jitpack should know about it, so it should be available soon.

https://github.com/Zhuinden/realm-monarchy/releases/tag/0.7.1

https://github.com/Zhuinden/realm-monarchy/commit/32369e5025510dffd3d5cebb65f293b25f7b2e89

Check if it makes your DB reads a bit saner. Report back if you experience crashes or whatnot, theoretically you shouldn't. Then again, theoretically Realm should have no native crashes. :smirk:

ganfra commented 4 years ago

Thanks for that! I already added my comment to an existant issue on realm repo about crashes on 7.0.0

Zhuinden commented 4 years ago

Report back if frozen results helped, theoretically I think out of all the things that Monarchy offers (copied, paged, frozen), frozen should be the fastest.

I also think what Monarchy offers is actually something that Realm should be able to do out of the box, but that's a different line of thought.

ganfra commented 4 years ago

I mostly use mapped as I expose model through a SDK, but I still need it for some cases. But I wait for the crashes to be solved first ;)