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

Reply via email to