-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread handoff for RealmObject and RealmResults / Frozen state #1208
Comments
Any progress? |
Following the discussion on last weeks offsite-meeting. We gravitated towards the following pattern:
Adding a
We need the new snapshot concept from core though to not run out of memory really really fast. |
Thanks for the updates @cmelchior! but what exactly would be "frozen" when we call in other words, are you taking a snapshot of the entire object graph that can be linked to from the frozen object? |
It would give you a completely consistent view of all linked data as well. This is actually what is already happening today across threads. The |
|
Depending on what you mean by requerying the Something like Do you have a particular use cases in mind? We haven't set anything set in stone yet, so any feedback on potential use cases are very welcome as that might effect how the API is designed. Thinking about this a bit more then it would probably make more sense to not let |
@cmelchior I don't have a specific use case in mind. And you're absolutely right about consistency issues; my thinking was more about being about to do a sanity check. Also, instead of having |
Some sort of type-safety might actually not be a bad idea. I am not sure that approach is possible with single objects as we would have to generate classes visible to the user though the annotation processor, which is a pretty painful process. It is worth a second though. |
> You wouldn't be able to "unfreeze" a RealmResults to make it live-update
again I think. That would just open up a host of potential pitfalls.
If we go in this direction we have to be really clear about specifying how
these objects (and the result of any action on them) can be used. The
results of returning these new "frozen" objects to the originating Realm
(like on the UI thread) could have quite unintuitive consequences. You
could end up with duplicates of the same object, or if you use upsert,
accidentally revert them to an earlier state, or they could have been
deleted in the mean time... All stuff that could potentially result in bugs
that would be very hard to debug.
|
Any update on if the |
@craig-enquos Yes, if not with this exact API then in some way the functionality will be provided. We don't have any timeline yet though. |
What's the status on this? Is there still no way to use subscribeOn(Schedulers.io()) with observeOn(AndroidSchedulers.mainTHread())? |
+1 would love to see this. |
@cmelchior I do wonder though, realm results that are no longer used still update themselves on Frozen state would make RealmResults more CPU-friendly when the view/activity/fragment that created them no longer exists, because they wouldn't be updating a results that's no longer needed by anyone. Just a random thought. |
Yes! But IMO, the easy way to make it more CPU-friendly it just call |
@beeender wait a second,
|
@Zhuinden I misunderstood your point, sorry... Yeah, as long as they are not GCed they are still get updated when db changes. It is not difficult to supply a API to close the |
@beeender Well in cases when you replace a RealmResults with a new RealmResults because your filter condition is based on input from the user ( |
Yes. I think a |
I'm not inherently against it, but then again, adding an optional |
I want My reason is my believe that devs knows much more about context than the library and should have much control of allocation/deallocation as possible, to a point without having the library/API feel like C code code where everything is free() this and free() that. I think some closeable() interface in realm can co-exist with finalizer and future phantom queues. Best of both worlds. |
A very common case for me
I would start realm from the thread i'm processing the results but it's not that easy and it messes up with my structure. We need to be able to jump threads with the results. Although, copyFromRealm is a solution, it's has a big performance hit when you have large results. |
@ArthurSav Well if you use Realm as intended RealmRecyclerViewAdapter adapter = //... use recycler adapter which handles change events naturally
getRealm().where(Venue.class)
.findAllAsync() //5k venues // use on UI thread, `async` method is already async
.asObservable()
//.map(venues -> venues.subList(0, 2000)) // you already get a RealmResults<T> here, just index from 0...,min(1999, venues.size()-1)
//.map(venues -> getRealm().copyFromRealm(venues)) //big performance hit // zero copy
.filter(RealmResults::isLoaded()) // only load Results if they're loaded
//.doOnNext(venues -> jumpThread(venues)) //don't jump thread, call on UI thread
.subscribe(venues -> adapter.updateData(venues)); In short getRealm().where(Venue.class)
.findAllAsync()
.asObservable()
.filter(RealmResults::isLoaded())
.subscribe(venues -> adapter.updateData(venues)); Then you won't have this problem. See my RecyclerView example. |
@Zhuinden I don't see how you example is relevant. |
@ArthurSav then I don't see why the query is not a synchronous query on a background thread then, directly throwing the RealmResults into the parser with Don't forget, Realm is zero-copy only if you don't explicitly copy everything from it. If you rip out the entire database into memory, that's expected to take a while. |
With the new changes in Core6 (#6107). This feature should now be possible. We need the following changes: Suggested public API changes:
We need to determine the semantics for Internal changes:
|
It should be possible to move objects and query results between threads seamlessly. The underlying concepts introduced in #896 should be useable for this as well.
The text was updated successfully, but these errors were encountered: