On Fri, May 22, 2015 at 5:06 PM, Paul Merlin <[email protected]> wrote:
> Niclas Hedhman a écrit : > > There is this sub-optimal section in the ValueBuilderWithPrototype.java > > > > // @TODO there is probably a more efficient way to do this > > ValueSerialization valueSerialization = > currentModule.valueSerialization(); > > String serialized = valueSerialization.serialize( prototype ); > > value = valueSerialization.deserialize( valueModel.valueType(), > serialized); > > > > And this approach is of course a performance hog, as well as introducing > a > > strange problem about initializing ValueComposites with Associations. > > > > And it should be required to clone via serialization, but I understand > that > > the effort might be substantial... Any takers?? > Couldn't it be replaced by programmatic cloning of underlying > AssociationStateHolder? Not trivial though. > Yes, I think that is how it should be done, and yes, I agree it isn't trivial, since the Prototype object is Mutable, although the resulting ValueInstance isn't. A different approach could be "late cloning". I am not sure that my apps are typical or not, but I very seldom use the prototyping feature, and almost always "1 ValueBuilder per instantiated Value". And if that is the most common case, yet we don't want to give up the "prototype instance stamping" feature, I think it is possible to clone from the "last created object into the 'new' prototype" when user try to set some prototype property after newInstance(). That might actually be easier to implement. AND, then we can look at whether "prototype instance stamping" is faster than creation of a new ValueBuilder. IF NOT, then it would make sense to do the Prototype feature at a higher level, perhaps in 3.0, possibly by leveraging Concerns and have it is a library instead. * I imagine that Concerns could cache the property set() calls, and on newInstance() populate the ValueBuilder from scratch. No time to flesh out the details here. Cheers -- Niclas Hedhman, Software Developer http://zest.apache.org - New Energy for Java
