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
olonho
05/24/2018, 6:32 AM
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
louiscad
05/24/2018, 6:36 AM
@olonho So freezing one object freezes the ones it references?
o
olonho
05/24/2018, 6:45 AM
yes, freezing is a transitive operation
s
spierce7
05/25/2018, 3:57 PM
@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
olonho
05/25/2018, 5:00 PM
copying is a semantically non-trivial operation, so it shall be usually implemented by the programmer