I just did a micro benchmark to see which is faster.

The project is here:

https://github.com/dashorst/wicket-benchmarks

You can see the test code here:

https://github.com/dashorst/wicket-benchmarks/blob/master/src/main/java/com/martijndashorst/wicketbenchmarks/LambdaModels.java

The results are (on my laptop) for this particular run (10 warmup
rounds for each iteration of 1s, each benchmark consists of 10
iterations of 10 seconds each):

LambdaModels.nativeEvaluation       thrpt   10  357854132.948 ±
5459963.153  ops/s
LambdaModels.abstractReadOnlyModel  thrpt   10  261693660.899 ±
2008898.403  ops/s
LambdaModels.directLambdaModel      thrpt   10  216231074.508 ±
3866874.908  ops/s
LambdaModels.chainedLambdaModel     thrpt   10  152373429.346 ±
938206.534  ops/s
LambdaModels.propertyModel          thrpt   10    2180390.984 ±
72875.218  ops/s

In other words:

if property model has performance of 1, a chained lamda has a better
performance of 70x that. The direct lambda model has a performance of
99x a property model, retrieving a property value directly using a
abstract read only model is 120x more performant than a property
model. And just directly getting the value of the property without
wrapping it in a model is 164x faster than using a property model.

Will this matter? Probably a little bit for your overall application
if it is heavily used. If you have a page with lots of property models
you can do a lot better by using lambda models if you need the
dynamism.

Martijn


On Thu, Nov 10, 2016 at 1:38 PM, Martijn Dashorst
<[email protected]> wrote:
> IModel<String> m =
>   LoadableDetachableModel
>     .of(Person::new)
>     .map(Person::getName);
>
> So much sexiness with lambda's and models...
>
> IModel<Account> a = ...;
> IModel<Person> p = a.map(Account::getPerson);
>
> add(new Label("firstName", p.map(Person::getFirstName));
> add(new Label("lastName", p.map(Person::getLastName));
>
> Too bad Java doesn't have properties as a language construct. That
> would make this even better:
>
> IModel<Account> a = ...;
> IModel<Person> p = a.map(Account::person);
>
> add(new Label("firstName", p.map(Person::firstName));
> add(new Label("lastName", p.map(Person::lastName));
>
> Martijn
>
> On Thu, Nov 10, 2016 at 1:17 PM, Martin Grigorov <[email protected]> wrote:
>>  grep Label | grep '::' wicket-examples/src/main/java/
>> wicket-examples/src/main/java/org/apache/wicket/examples/
>> ajax/builtin/FileUploadPage.java
>> 87: form.add(new Label("max", form::getMaxSize));
>>
>> wicket-examples/src/main/java/org/apache/wicket/examples/
>> ajax/builtin/GuestBook.java
>> 78: listItem.add(new Label("date", comment::getDate));
>>
>> wicket-examples/src/main/java/org/apache/wicket/examples/
>> compref/LabelPage.java
>> 45: add(new Label("dynamicLabel", Date::new));
>>
>> wicket-examples/src/main/java/org/apache/wicket/examples/
>> compref/LinkPage.java
>> 48: link1.add(new Label("label1", count1::toString));
>>
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>> On Thu, Nov 10, 2016 at 1:05 PM, Emond Papegaaij <[email protected]
>>> wrote:
>>
>>> Didn't we make IModel a functional interface with default methods for
>>> setObject and detach? In that case, you can simply use a method reference
>>> as
>>> your model.
>>>
>>> Emond
>>>
>>> On donderdag 10 november 2016 12:56:50 CET Martijn Dashorst wrote:
>>> > I'm working on replacing my AROM's and often they just call a getter.
>>> > In that case I'd rather use a method reference than doing the IModel
>>> > replacement.
>>> >
>>> > Is there a reason why the LambdaModel doesn't have a path for only a
>>> getter?
>>> >
>>> > This way I can do:
>>> >
>>> > public A(String p, final SerializableSupplier<Boolean> visibility)
>>> > {
>>> >     this(p);
>>> >     condition = LambdaModel.of(visibility);
>>> > }
>>> >
>>> > instead of:
>>> >
>>> > public A(String p, final SerializableSupplier<Boolean> visibility)
>>> > {
>>> >     this(p);
>>> >     condition = new IModel<Boolean>() {
>>> >         private static final long serialVersionUID = 1L;
>>> >
>>> >         @Override
>>> >         public Boolean getObject() {
>>> >             return visibility.get();
>>> >         }
>>> >     };
>>> > }
>>> >
>>> > I have the code ready to push, shall I?
>>> >
>>> > Martijn
>>>
>>>
>>>
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com

Reply via email to