r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
403 stars 56 forks source link

Add get_state and set_state functionality to R6 objects #197

Closed d-sharpe closed 4 years ago

d-sharpe commented 4 years ago

When saving and loading R6 objects (via serialization) the objects consume more greater amounts of memory after load. It appears that the unserialization process creates copies of function bodies. The effect is large for nested and recursive objects. #157

Added an instantiate method to the R6 class generator, (essentially the new() method without calling to initialize) allowing creation of an uninitialized 'blank' object.

Added default public methods of get_state and set_state which return and accept a nested list of field values representing the 'state' of the object. Can be overridden by user supplied public get_state and set_state methods.

Added internal binding to public interface with instance uuid. Used in conjunction with get/set_state to distinguish between to instances of same class

wch commented 4 years ago

I appreciate the intent, but these changes are much more invasive than I'm willing to take for the problem it is intended to solve. (Side note: examples and some documentation would be very helpful for reviewers.)