To reuse instance or not

I remember seeing in several places that we shouldn’t re-use a Realm instance. My interpretation of that is that I should always call as the first step of any query. In my implementation of Realm however, I’ve noticed that reusing the same instance saves me around ~12ms on every single query when I compare it to creating a new instance.

For my application, 12ms is huge, because it’s enough to freeze the UI on low end devices.

To the left is when I’m reusing the instance. To the right is when I’m creating a new instance for each query.

As you can see, approximately 12ms is added on each subsequent query.

  1. Am I doing things wrong?
  2. Is there any way around this?
  3. What risks am I taking by reusing the instance?
  4. Is this because of the amount of schemas (around 25 in total) I have? And if so - is there some kind of solution to this?

This is roughly how I open an instance:

      schema: schemas,
      schemaVersion: Object.keys(this.migrations).length,
      onMigration: (oldRealm, newRealm) => {
        Object.entries(this.migrations).forEach(([key, migration]) => {
          if (oldRealm.schemaVersion < key) {
            migration?.(oldRealm, newRealm)