-
Notifications
You must be signed in to change notification settings - Fork 68
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
App not Responding when Realm Configuration is created #1544
Comments
Hmm, the problem seems to start here when we try to look at the companion class of the RealmObjects that are part of the schema, which for some reason does not work correctly. How are these schema model classes defined? In the same module? A different module? Also, do they already have a companion object? |
@cmelchior These are defined in same module.All of them have a companion object of Type InstanceFactory like this one
|
You might be running into this issue then: #91 Granted that issue was created some time ago, and both the version of Kotlin and how we generate the code have changed since, but would it be possible for you to test this by removing the companion object? It should be possible to test just with a subset of the schema where the companion object is removed |
@cmelchior I am going ahead with removing companion objects from RealmObject Entities. Unfortunately it will take some for me to come back with results since we only get this in production with limited set of users facing this. |
@cmelchior This is still happening even after moving companion objects out of Entity classes.
|
@rishabh876 Is it possible for you to reproduce this issue in a sample project we can debug? |
Running into similar issues on low end devices. Very suprised the a configuration builder would be performing such expensive operations. To initialize the builder Emulator on a Macbook M1 is ~1-4s to initialize the builder On a low end device a debug build with a small schema around 6 objects will take ~10s and our very large schema realm with around 100 objects takes ~25s on a low end device. It seems the reflection logic is very inefficient. We did have companion objects in the realm models and removing them did not change the performance or had minimal impact. |
Hmm, interesting datapoints. We don't look at any classes using reflection, we just check that the companion objects have specific interfaces. We do build up a lot of schema information though, which involves roundtrips through JNI. This happens when you open the Realm, and that does scale with the number of classes and properties. But it is still a bit surprising it takes that long. Out of curiosity, how many properties does each class have (on average)? We did have it on our radar that it was something we wanted to optimize, but it sounds like we need to bump the priority on that. Because 25 seconds definitely sounds like way too long. This is being tracked here btw: #1073 |
Right was referring to usage of Not sure what the average number of properties are but 2-6 typically, probably closer to 2-3 on average. To test the impact I used this to replicate the constructor logic
Tested on two realm schemas. Emulator Low end device This is also happening on app start on a background thread with a debug build Unit test performance Attaching our small schema (6 objects) |
Any update on this? Now that @ashare80 has shared reproducible code, we should remove |
We haven't investigated the reproduction case yet, but it is on our radar. |
Hi @ashare80 and @rishabh876. I cannot provoke anything like your observations when trying to use a low profile emulator. Don't know if this would showcase on an emulator though, but could you share details of the "low end devices":
So that we can establish a common basis for the investigations. |
The worst performance we have is on this custom hardware. Android version: 11 |
@rorbech I just realised that even though I have removed companion objects from Entities, there are companion objects inside interfaces that these entities implement. Can those companion object lead to this? Also can we add a configuration that ignores companion objects during this reflection step as a work around? |
I have played around with various emulator configurations but cant provoke this, and do not currently have access to low profile devices to test it on. I can't really see how the embedded companion objects should affect this, but it could be worth a try. The previous shared "reproducible code" is not a standalone project that shows the problem, so the triggering factor could might as well be outside the scope of the model definition (e.g. number of classes in the whole app, etc.). The reflection code is in fact trying to find the companion objects as the static model definition is compiled into those, and as this is kotlin-stdlib code we can't really tweak it. Only option would be to offer another schema configuration option, where you manually registered the companion objects. This would allow to skip reflection code at all. But it is not the easiest workaround and until we have a way to replicate the issue we have no way of evaluating if the workaround is feasible. |
Hi guys, As an option, you could allow disabling schema verification (we would disable it for release builds) for |
How frequently does the bug occur?
Sometimes
Description
Many of our users are facing a lot of ANRs on app launch. This happens when Koin dependencies are injected on Application onCreate. From the stacktrace it looks like its always stuck in RealmConfiguration build Step.
I have not been able to reproduce this ANR so far.
Stacktrace & log output
The text was updated successfully, but these errors were encountered: