Read performance ~125 times slower using cached user

For context, imagine a Realm containing about 100 of “Person” objects each with a “lastName” property.

Creating a dictionary the following way:
let dict = Dictionary(grouping: realm.objects(Person.self), by: { $0.lastName })

The above line takes ~0.6 milliseconds to execute if done in the same session after calling app.login(credentials:), but if I try to execute the same line after terminating the app and reopening it without logging in, it takes ~75 milliseconds.

Is this kind of performance normal?

Calling login() does perform a network call so I would expect there to be additional latency when going through that codepath. After logging in though, all realm reads and writes will be to local disk so the latency should be the same. You also do not need to login with every app launch, the user credentials are cached so you can simply call currentUser() to open a local realm for access without needing to relogin.

Hi Ian, thanks for the quick reply.

The issue here is that if I don’t call login() every app launch, the performance of that single line of code mentioned in my original post is over 100 times slower.