How to upsert correctly with kotlin-realm?

Hi,

I am currently working on a Spring Backend which uses realm-kotlin to create a realm-database, it is later saved as a zip file and provided via api to apps.

I am working with “nested” RealmObjects with occure in multiple places of my “root” RealmObject. Those RealmObjects have PrimaryKeys

val config = RealmConfiguration.Builder(setOf(
            // classes
        )
            .compactOnLaunch()
            .build()

        val realm = Realm.open(config)
        realm.writeBlocking {
      
            data.forEach {
                this.copyToRealm(it, UpdatePolicy.ALL)
            }
        }

        realm.close()
        
      // create zip  
    }

However, I observe that the resulting realm db file is much larger than a realmdb file which was created with the swift sdk.
If I dont specify UpdatePolicy.ALL (it defaults to ERROR) the creation fails due to already existing objects with already existing primary keys which is expected. However, I guess that UpdatePolicy.ALL leads to massive updates on already existing objects, resulting in a large number of object versions?
If this is the case and the problem I am not sure how to solve it with realm-kotlin. I saw that the swift sdk has a UpdatePolicy.MODIFIED which only updates when the values actually differ which is what I would need.

The java sdk has also something similar.

I would greatly appreciate any hints regarding this issue