You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Emond Papegaaij <em...@topicus.nl> on 2016/11/15 10:29:59 UTC

Implementation of LambdaModel

Hi,

Martijn was doing some memory benchmarking on models, including LambdaModel, 
so I decided to take a closer look at its current implementation. First of 
all, I've got some doubts about the current implementation of equals and 
hashCode: are 2 LambdaModels really equal when their getters and setters are 
equal? IMHO we should just leave those methods out, just as with 
PropertyModel.

Next, I took a look at its current memory consumption, and managed to get a 
significant improvement without changing the API much. The only change is that 
my new implementation is abstract and its constructor is private, so you can 
only get instances using the factory methods. Results for the 4 factory 
methods are:

of(SerializableSupplier<T>)
No change in memory: 72 bytes (implementation remained the same)

of(SerializableSupplier<T>, SerializableConsumer<T>)
No change in memory: 96 bytes

of(IModel<X>, SerializableFunction<X, T>)
Major reduction in memory usage: 80 vs. 120 bytes

of(IModel<X>, SerializableFunction<X, T>, SerializableBiConsumer<X, T>)
Major reduction in memory usage: 96 vs. 144 bytes

I've managed to get these improvements by making LambdaModel an abstract class 
and creating specific implementations for all three methods. Currently, 2 
testcases in LambdaModelTest fail due to the changes in hashCode an equality. 
Shall I drop these?

Best regards,
Emond

Re: Implementation of LambdaModel

Posted by Sven Meier <sv...@meiers.net>.
Hi,

 >are 2 LambdaModels really equal when their getters and setters are equal?

I don't think this is a necessity or useful anyway.

 >I've managed to get these improvements by making LambdaModel an 
abstract class
 >and creating specific implementations for all three methods.

Sounds good.

Have fun
Sven



Am 15.11.2016 um 11:29 schrieb Emond Papegaaij:
> Hi,
>
> Martijn was doing some memory benchmarking on models, including LambdaModel,
> so I decided to take a closer look at its current implementation. First of
> all, I've got some doubts about the current implementation of equals and
> hashCode: are 2 LambdaModels really equal when their getters and setters are
> equal? IMHO we should just leave those methods out, just as with
> PropertyModel.
>
> Next, I took a look at its current memory consumption, and managed to get a
> significant improvement without changing the API much. The only change is that
> my new implementation is abstract and its constructor is private, so you can
> only get instances using the factory methods. Results for the 4 factory
> methods are:
>
> of(SerializableSupplier<T>)
> No change in memory: 72 bytes (implementation remained the same)
>
> of(SerializableSupplier<T>, SerializableConsumer<T>)
> No change in memory: 96 bytes
>
> of(IModel<X>, SerializableFunction<X, T>)
> Major reduction in memory usage: 80 vs. 120 bytes
>
> of(IModel<X>, SerializableFunction<X, T>, SerializableBiConsumer<X, T>)
> Major reduction in memory usage: 96 vs. 144 bytes
>
> I've managed to get these improvements by making LambdaModel an abstract class
> and creating specific implementations for all three methods. Currently, 2
> testcases in LambdaModelTest fail due to the changes in hashCode an equality.
> Shall I drop these?
>
> Best regards,
> Emond