diff options
7 files changed, 232 insertions, 31 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 5cfad18540..34cdb70b2b 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -1121,6 +1121,8 @@ public class Escalator extends Widget private double defaultRowHeight = INITIAL_DEFAULT_ROW_HEIGHT; + private boolean initialColumnSizesCalculated = false; + public AbstractRowContainer( final TableSectionElement rowContainerElement) { root = rowContainerElement; @@ -1324,21 +1326,28 @@ public class Escalator extends Widget if (isAttached()) { paintInsertRows(index, numberOfRows); + /* + * We are inserting the first rows in this container. We + * potentially need to set the widths for the cells for the + * first time. + */ if (rows == numberOfRows) { - /* - * We are inserting the first rows in this container. We - * potentially need to set the widths for the cells for the - * first time. - */ - Map<Integer, Double> colWidths = new HashMap<>(); - for (int i = 0; i < getColumnConfiguration() - .getColumnCount(); i++) { - Double width = Double.valueOf( - getColumnConfiguration().getColumnWidth(i)); - Integer col = Integer.valueOf(i); - colWidths.put(col, width); - } - getColumnConfiguration().setColumnWidths(colWidths); + Scheduler.get().scheduleFinally(() -> { + if (initialColumnSizesCalculated) { + return; + } + initialColumnSizesCalculated = true; + + Map<Integer, Double> colWidths = new HashMap<>(); + for (int i = 0; i < getColumnConfiguration() + .getColumnCount(); i++) { + Double width = Double.valueOf( + getColumnConfiguration().getColumnWidth(i)); + Integer col = Integer.valueOf(i); + colWidths.put(col, width); + } + getColumnConfiguration().setColumnWidths(colWidths); + }); } } } @@ -4001,6 +4010,9 @@ public class Escalator extends Widget private boolean measuringRequested = false; public void setWidth(double px) { + Profiler.enter( + "Escalator.ColumnConfigurationImpl.Column.setWidth"); + definedWidth = px; if (px < 0) { @@ -4016,6 +4028,9 @@ public class Escalator extends Widget } else { calculatedWidth = px; } + + Profiler.leave( + "Escalator.ColumnConfigurationImpl.Column.setWidth"); } public double getDefinedWidth() { @@ -4389,24 +4404,32 @@ public class Escalator extends Widget return; } - for (Entry<Integer, Double> entry : indexWidthMap.entrySet()) { - int index = entry.getKey().intValue(); - double width = entry.getValue().doubleValue(); + Profiler.enter("Escalator.ColumnConfigurationImpl.setColumnWidths"); + try { - checkValidColumnIndex(index); + for (Entry<Integer, Double> entry : indexWidthMap.entrySet()) { + int index = entry.getKey().intValue(); + double width = entry.getValue().doubleValue(); - // Not all browsers will accept any fractional size.. - width = WidgetUtil.roundSizeDown(width); - columns.get(index).setWidth(width); + checkValidColumnIndex(index); - } + // Not all browsers will accept any fractional size.. + width = WidgetUtil.roundSizeDown(width); + columns.get(index).setWidth(width); - widthsArray = null; - header.reapplyColumnWidths(); - body.reapplyColumnWidths(); - footer.reapplyColumnWidths(); + } - recalculateElementSizes(); + widthsArray = null; + header.reapplyColumnWidths(); + body.reapplyColumnWidths(); + footer.reapplyColumnWidths(); + + recalculateElementSizes(); + + } finally { + Profiler.leave( + "Escalator.ColumnConfigurationImpl.setColumnWidths"); + } } private void checkValidColumnIndex(int index) diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index a58418d443..0b0642668f 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -5002,7 +5002,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, if (this.sortable != sortable) { this.sortable = sortable; if (grid != null) { - grid.refreshHeader(); + grid.getHeader().requestSectionRefresh(); } } return this; @@ -5035,7 +5035,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, if (this.resizable != resizable) { this.resizable = resizable; if (grid != null) { - grid.refreshHeader(); + grid.getHeader().requestSectionRefresh(); } } return this; @@ -8720,12 +8720,14 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, protected void onAttach() { super.onAttach(); + // Grid was just attached to DOM. Column widths should be + // calculated. + recalculateColumnWidths(); + if (getEscalator().getBody().getRowCount() == 0 && dataSource != null) { setEscalatorSizeFromDataSource(); } - // Grid was just attached to DOM. Column widths should be calculated. - recalculateColumnWidths(); for (int row : reattachVisibleDetails) { setDetailsVisible(row, true); } diff --git a/tests/screenshots b/tests/screenshots -Subproject f11893e9d3a12945497d47ae0ed0d45d0103ccc +Subproject b34376d7a98315719850d484124791ae9425cdb diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridManyColumns.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridManyColumns.java new file mode 100644 index 0000000000..7dca082a62 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridManyColumns.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.components.grid; + +import java.util.stream.IntStream; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; + +/** + * Test UI for Grid initial rendering performance profiling. + */ +@Widgetset("com.vaadin.DefaultWidgetSet") +public class GridManyColumns extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid<String> grid = new Grid<>(); + grid.setSizeFull(); + for (int i = 0; i < 80; i++) { + grid.addColumn(row -> "novalue").setCaption("Column_" + i) + .setWidth(200); + } + grid.setItems(IntStream.range(0, 10).boxed().map(i -> "")); + addComponent(grid); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridManyColumnsV7.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridManyColumnsV7.java new file mode 100644 index 0000000000..0dc2a60887 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridManyColumnsV7.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.components.grid; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.data.Container.Indexed; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; + +/** + * Test UI for Grid initial rendering performance profiling. + */ +@Widgetset("com.vaadin.v7.Vaadin7WidgetSet") +public class GridManyColumnsV7 extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setSizeFull(); + for (int i = 0; i < 80; i++) { + grid.addColumn("Column_" + i).setWidth(200); + } + grid.setContainerDataSource(createContainer()); + addComponent(grid); + } + + private Indexed createContainer() { + Indexed container = new IndexedContainer(); + + container.addContainerProperty("foo", String.class, "foo"); + container.addContainerProperty("bar", Integer.class, 0); + // km contains double values from 0.0 to 2.0 + container.addContainerProperty("km", Double.class, 0); + for (int i = 0; i < 80; ++i) { + container.addContainerProperty("Column_" + i, String.class, + "novalue"); + } + + for (int i = 0; i <= 10; ++i) { + Object itemId = container.addItem(); + Item item = container.getItem(itemId); + for (int j = 0; j < 80; ++j) { + item.getItemProperty("Column_" + j).setValue("novalue"); + } + } + + return container; + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridManyColumnsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridManyColumnsTest.java new file mode 100644 index 0000000000..c95a01fd1d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridManyColumnsTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 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.grid; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that Grid gets correct height based on height mode, and resizes + * properly with details row if height is undefined. + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridManyColumnsTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-grid")); + } + + @Test + public void testGridPerformance() throws InterruptedException { + long renderingTime = testBench().totalTimeSpentRendering(); + long requestTime = testBench().totalTimeSpentServicingRequests(); + System.out.println("Grid with many columns spent " + renderingTime + + "ms rendering and " + requestTime + "ms servicing requests (" + + getDesiredCapabilities().getBrowserName() + ")"); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridManyColumnsV7Test.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridManyColumnsV7Test.java new file mode 100644 index 0000000000..dce96dfd43 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridManyColumnsV7Test.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 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.grid; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that Grid gets correct height based on height mode, and resizes + * properly with details row if height is undefined. + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridManyColumnsV7Test extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-grid")); + } + + @Test + public void testGridPerformance() throws InterruptedException { + long renderingTime = testBench().totalTimeSpentRendering(); + long requestTime = testBench().totalTimeSpentServicingRequests(); + System.out.println("Grid V7 with many columns spent " + renderingTime + + "ms rendering and " + requestTime + "ms servicing requests (" + + getDesiredCapabilities().getBrowserName() + ")"); + } + +} |