How many simultaneous RealmCollection observations can you have?


this might be a strange question, but is there a practical/hard limit on how many observations I can simultaneously run on the database? By observation I mean these:

let results = realm.objects(MyObject.self).where { /* ... */ }
let token = results.observe { /* ... */ }

I want to run some kind of continuous set of analyses on the objects in a database in the background, and I’m thinking about having multiple queries that observe changes and do something with the result. For example (just to demonstrate):

  • Observe all objects added today
  • Observe all objects with multiple url strings attached
  • Observe all objects with no title
  • Observe all objects older than two weeks
  • And so on…

I wouldn’t have hundreds of these, but they could add up to maybe a dozen or more eventually. I’m just trying to figure out if an approach, in which I observe many queries simultaneously is feasible or if that is a bad idea with Realm.

Can the database/framework handle this, or should I reduce the observations to a smaller number of queries (i.e. have a broader query that includes more items and filter through them “manually”)


Sorry for the delayed response.

Adding a ‘bunch’ of observers is how Realm is designed to operate so couple dozen has no real impact.

One thing to keep in mind is that collection change observers don’t support high-frequency updates. Now what ‘high frequency’ actually means is debatable (and vague - thanks docs!) but if multiple objects are changing every second, that’s probably too much.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.