How to use compactOnLaunch effectively


#1

I have two questions regarding compactOnLaunch that considers stability and performance when building a RealmConfiguration:

Performance Question
Is it an expensive to add compactOnLaunch to your Realm builder configuration?
Is it only expensive when the default implementation (DefaultCompactOnLaunchCallback) return true (i.e. only when the compaction occurs)?

I was thinking of selectively adding compactOnLaunch to the configuration once every week by keeping track of it in the app config (Preferences).

Question around implementation
I also noticed that adding the one liner compactOnLaunch to my Realm Config builder, I had to change myt implementation so that I do not return a new instance of the RealmConfig but define a singleton class that holds on the reference of that RealmConfig for any subsequent creation of a Realm instance.

I am confused as to why it was not error prone to create a new Realm instance with a new instance of the RealmConfiguration when compactOnLaunch was not added to the builder. Can someone explain this behaviour?

I am using Realm Java for Android io.realm:realm-gradle-plugin:3.7.2

Thank you!