diff options
author | jotatu <jotatu@g-10-64-12-127.guest.vaadin.com> | 2015-08-07 14:45:50 +0300 |
---|---|---|
committer | Patrik Lindström <patrik@vaadin.com> | 2015-11-05 12:47:16 +0200 |
commit | 9c1908d0a5fdba09167414e837cc08a2f746584b (patch) | |
tree | fe8fec7d5118134d72af5c7de49890bba8b2bd0c /uitest | |
parent | 2b8cd659685c48fd6284ba3566009b2285132751 (diff) | |
download | vaadin-framework-9c1908d0a5fdba09167414e837cc08a2f746584b.tar.gz vaadin-framework-9c1908d0a5fdba09167414e837cc08a2f746584b.zip |
Optimize layout performance of Table (#17947)
Adds functions for skipping child component layout measuring.
Removes unnecessary code from VScrollTable.
1. case: no components
- render time without the fix: ~105ms
- render time with fix: ~105ms
2. case: 2 button and 2 textfield cols
- render time without the fix: ~279ms
- render time with fix: ~240ms (~17% faster)
3. case: 3 button and 3 textfield cols
- render time without the fix: ~350ms
- render time with fix: ~281ms (~20% faster)
Change-Id: I6025f8ee2fd438d228ff3b65f43535961cf12c0b
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHint.java | 184 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHintTest.java | 45 |
2 files changed, 229 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHint.java b/uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHint.java new file mode 100644 index 0000000000..dd5d162e17 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHint.java @@ -0,0 +1,184 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractOrderedLayout; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.DateField; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HasChildMeasurementHint.ChildMeasurementHint; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; + +public class TableChildMeasurementHint extends AbstractTestUI { + + private HorizontalLayout buttonLayout = new HorizontalLayout(); + private HorizontalLayout layout; + private Table table1, table2, table3; + + @Override + public void setup(VaadinRequest request) { + initMain(); + } + + protected void initMain() { + ((AbstractOrderedLayout) getContent()).setMargin(false); + layout = new HorizontalLayout(); + layout.setSpacing(true); + layout.setMargin(false); + layout.setSizeFull(); + addComponent(buttonLayout); + addComponent(layout); + + table1 = createTable(); + table1.setSizeFull(); + table1.setChildMeasurementHint(ChildMeasurementHint.MEASURE_ALWAYS); + + table2 = createTable(); + table2.setSizeFull(); + table2.setChildMeasurementHint(ChildMeasurementHint.MEASURE_IF_NEEDED); + + table3 = createTable(); + table3.setSizeFull(); + table3.setChildMeasurementHint(ChildMeasurementHint.MEASURE_NEVER); + + buttonLayout.addComponent(new Button("Show table1", + new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + layout.addComponent(table1); + table1.focus(); + } + })); + buttonLayout.addComponent(new Button("Show table2", + new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + layout.removeComponent(table1); + layout.addComponent(table2); + table2.focus(); + } + })); + buttonLayout.addComponent(new Button("Show table3", + new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + layout.removeComponent(table2); + layout.addComponent(table3); + table3.focus(); + } + })); + + } + + protected Table createTable() { + Table table = new Table(); + table.setSelectable(true); + table.setPageLength(39); + + for (int i = 0; i < 5; i++) { + table.addContainerProperty("First_Name" + i, String.class, null); + table.addContainerProperty("Last Name" + i, String.class, null); + table.addContainerProperty("Year" + i, Integer.class, null); + } + + /* Add a few items in the table. */ + int j = 0; + for (int i = 0; i < 2; i++) { + table.addItem( + makeRow(new Object[] { "Nicolaus" + i, "Copernicus", 1473 }, + 5), j++); + table.addItem( + makeRow(new Object[] { "Tycho" + i, "Brahe", 1546 }, 5), + j++); + table.addItem( + makeRow(new Object[] { "Giordano" + i, "Bruno", 1548 }, 5), + j++); + table.addItem( + makeRow(new Object[] { "Galileo" + i, "Galilei", 1564 }, 5), + j++); + table.addItem( + makeRow(new Object[] { "Johannes" + i, "Kepler", 1571 }, 5), + j++); + table.addItem( + makeRow(new Object[] { "Isaac" + i, "Newton", 1643 }, 5), + j++); + } + + table.addGeneratedColumn("First_Name" + 0, new Table.ColumnGenerator() { + @Override + public Object generateCell(Table components, Object o, Object o2) { + ComboBox b = new ComboBox("ComboBox"); + b.setWidthUndefined(); + return b; + } + }); + + table.addGeneratedColumn("First_Name" + 1, new Table.ColumnGenerator() { + @Override + public Object generateCell(Table components, Object o, Object o2) { + GridLayout b = new GridLayout(); + b.addComponents(new Label("l1"), new Button("b"), new Label( + "l2")); + b.setWidthUndefined(); + return b; + } + }); + + table.addGeneratedColumn("First_Name" + 2, new Table.ColumnGenerator() { + @Override + public Object generateCell(Table components, Object o, Object o2) { + Button b = new Button("Button"); + b.setWidthUndefined(); + return b; + } + }); + + table.addGeneratedColumn("First_Name" + 3, new Table.ColumnGenerator() { + @Override + public Object generateCell(Table components, Object o, Object o2) { + TextField b = new TextField("Textfield"); + b.setWidthUndefined(); + return b; + } + }); + + table.addGeneratedColumn("First_Name" + 4, new Table.ColumnGenerator() { + @Override + public Object generateCell(Table components, Object o, Object o2) { + DateField b = new DateField("DateField"); + b.setWidthUndefined(); + return b; + } + }); + + table.addGeneratedColumn("First_Name" + 5, new Table.ColumnGenerator() { + @Override + public Object generateCell(Table components, Object o, Object o2) { + Label b = new Label("Label"); + b.setWidthUndefined(); + return b; + } + }); + + return table; + } + + protected Object[] makeRow(Object[] data, int c) { + Object[] row = new Object[c * data.length]; + for (int j = 0; j < c; j++) { + int x = 0; + for (Object value : data) { + row[j * data.length + x] = value; + x++; + } + } + + return row; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHintTest.java b/uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHintTest.java new file mode 100644 index 0000000000..8202b06362 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableChildMeasurementHintTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.table; + +import java.io.IOException; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableChildMeasurementHintTest extends MultiBrowserTest { + + @Test + public void testCacheSize() throws IOException { + + openTestURL(); + + $(ButtonElement.class).first().click(); + + compareScreen("initial"); + + $(ButtonElement.class).get(1).click(); + + compareScreen("initial"); + + $(ButtonElement.class).get(2).click(); + + compareScreen("initial"); + } + +} |