What is the performance hit for freezing an object...
# kotlin-native
s
What is the performance hit for freezing an object? If I freeze an object that has references to other objects, are they frozen as well? Let's say I have an object hierarchy of ~1000 objects, and freeze the root object. Why kind of performance hit are we talking about?
o
It depends on object graph topology, and if graph is acyclic - it’s pretty quick (i.e. single pass over reachable objects). If it contains cycles - there are more work to do, we have to build strongly connected components, and create aggregating container for each SCC. But feel free to measure that in your case.
l
@olonho So freezing one object freezes the ones it references?
o
yes, freezing is a transitive operation
s
@olonho Is there a way to copy an object tree before freezing? I was thinking we could use data classes to copy an object before freezing it, but a data class copy isn't transitive.
o
copying is a semantically non-trivial operation, so it shall be usually implemented by the programmer