Long delay before receiving realm notification when adding object to collection

We are busy testing migration to MongoDB Realm and are seeing quite significant delays or 2 -3 seconds before receiving notifications when adding objects to a realm collection from our RealmSwift application.

The application has a list of items showing and when the user clicks a “+” button a new item is added to the realm and the list is updated to show the new item.

Currently we are observing the Results from the realm query and when we get the update notification we update the list.

Why are we seeing a 2 - 3 second delay when adding items if the realm is a Synced realm ? Is there any way to improve the performance to ensure the user sees that a new item is added immediately ?

It doesn’t seem to matter if the new items are created on a background thread or simply created on the main thread.

Is this a change in behaviour from the Realm Cloud ?

Is there a recommended way to do such updates that will ensure the changes get seen in the local app immediately?


X-POST Slow notification when adding object to synced Realm (MongoDB Realm SDK V10.x) · Issue #7357 · realm/realm-cocoa · GitHub

@Duncan_Groenewald Can you please post in only one place please? We have limited resources

Sure - sorry. I thought it was a sync issue and then realised it probably wasn’t.

OK, so this is weird - if I run the app in Debug mode under Xcode then the notifications are being received ! Also it seems the Intel users are seeing the notifications coming through but for some reason the Apple Silicon version (macOS) is having trouble.

Well that didn’t last. It seems that for some reason it worked in debug just that one time. Subsequently it is not.
However the download/upload sync callback is getting called when the remote client makes a change to one of the collections so I am guessing the sync process is working but for some reason the change notifications are not getting called. Why they would work ONE TIME and then not the next time seems rather strange.

OK I think I found the problem.

When we open the synced realm the first time when the app gets launched by the user we do so from a background thread to avoid any issues with any realm-core database file format upgrades that might need to be run.

If this upgrade needs to be run then this causes the MAIN THREAD to block on the call to Realm() until the database file format upgrade has completed. This is obviously undesirable because the UI hangs.

If I remove this first time call to Realm() and do it from the MAIN THREAD then this issue of receiving change notifications appears to now go away.

Strange that the Intel macOS users don’t appear to have reported any problems with the UI not updating when other clients update the data.

So I guess the question is should it matter that the first time Realm() is called it is called from a background thread ? Is this a bug perhaps ?