Skip to content

Commit

Permalink
test: adjust test and add measurements
Browse files Browse the repository at this point in the history
The change improves the server side roundtrip processing time for 2000 buttons with click listeners from roughtly 210ms to 130ms (-40%)
by not eagerly creating the id using MessageDigest after evaluating each event data expression.

Difference to buttons without any click listeners is still about x2 (65ms->130ms).
  • Loading branch information
pleku committed Oct 26, 2021
1 parent 6b90b08 commit d38c768
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public String getId() {
}

/**
* Exports this key into a JSON object to send to the client. This
* method should be called only by the {@link ConstantPool} instance that
* manages this value. It may be called multiple times.
* Exports this key into a JSON object to send to the client. This method
* should be called only by the {@link ConstantPool} instance that manages
* this value. It may be called multiple times.
*
* @param clientConstantPoolUpdate
* the constant pool update that is to be sent to the client, not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,11 @@ public void eventUnregisterListener_outsideListenerTwiceThrows() {
@Test // #7826
public void addListener_eventDataExpressionsPresent_constantPoolKeyNotCreatedAfterEachExpression() {
final TestButton button = new TestButton();
try (MockedStatic<MessageDigestUtil> util = Mockito.mockStatic(MessageDigestUtil.class)){
util.when(() -> MessageDigestUtil.sha256(Mockito.anyString())).thenReturn(new byte[]{1,1,1,1,1,1,1,1,1,1,1,});
try (MockedStatic<MessageDigestUtil> util = Mockito
.mockStatic(MessageDigestUtil.class)) {
util.when(() -> MessageDigestUtil.sha256(Mockito.anyString()))
.thenReturn(
new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, });
button.addClickListener(event -> {
});
util.verifyNoInteractions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,13 @@ public void differentValue_differentId() {
Assert.assertNotEquals(constantId, otherId);
Assert.assertTrue(constantPool.hasNewConstants());
}

@Test
public void constantPoolKey_exportedDirectly_idCreated() {
final ConstantPoolKey constantPoolKey = new ConstantPoolKey(
Json.createObject());
final JsonObject message = Json.createObject();
constantPoolKey.export(message);
Assert.assertTrue(message.hasKey(constantPoolKey.getId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,37 @@

package com.vaadin.flow.uitest.ui;

import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.html.NativeButton;
import com.vaadin.flow.router.Route;

/* Manual test case for #7826 */
@Route("performance/constant-pool")
public class ConstantPoolPerformanceView extends AbstractDivView {

Div container = new Div();
Div notification = new Div();

public ConstantPoolPerformanceView() {
NativeButton btn = new NativeButton("refresh");
btn.addClickListener(e->{
NativeButton btn = new NativeButton(
"add 2k divs without click listener");
btn.addClickListener(e -> {
container.removeAll();
for (int i = 0; i < 2000; i++) {
container.add(new NativeButton("No click listener "));
}
});
NativeButton btn2 = new NativeButton("add 2k divs with click listener");
btn2.addClickListener(e -> {
container.removeAll();
for (int i = 0; i <1000; i++) {
container.add(new H1("Headline " + i));
container.add(new NativeButton("BTN " + i, e2 -> notification.setText("clicked")));
for (int i = 0; i < 2000; i++) {
container.add(new NativeButton("With click listener " + i,
e2 -> notification.setText("clicked")));
}
UI.getCurrent().getPage().executeJs("setTimeout(function(){$0.click()},2000)", btn);
});
add(btn,notification,container);
final NativeButton clearButtons = new NativeButton("clear buttons",
e -> container.removeAll());
add(btn, btn2, clearButtons, notification, container);
}

}

0 comments on commit d38c768

Please sign in to comment.