Open asyncLiz opened 5 years ago
Thanks for the report. Not sure if the solution proposal is valid since it checks the item equality with row._prevModel.item === model.item
which could evaluate to true
even if a sub-property of the item has changed. In that case a re-render would still be expected.
Example: The first demo (https://cdn.vaadin.com/vaadin-grid/5.2.5/demo/#grid-basic-demos) should update the "First Name" of the first item with the following:
const grid = $0;
grid.items[0].name.first = 'Foo';
grid.clearCache();
Edit: I see you already brought this up at ("..and all of its properties.."). Could be difficult to deep scan trough the diffs of the entire item object.
You could also provide some property or callback for the user to determine whether or not two items are equal.
html`
<vaadin-grid
.items="${items}"
.areItemsEqual="${(a, b) => a.id === b.id}"
>
</vaadin-grid>
`
That would prevent vaadin-grid from having to include a deep equality checker. You could even make this re-rendering logic optional and only enabled if the user provides a function to determine item equality.
Description
The grid renders cells multiple times when items are first set, even though the model does not change. The more complex the cells and the greater the number of columns, the worse the slowdown.
Expected outcome
A cell should only be re-rendered when the row model changes.
Actual outcome
Cells are rendered multiple times when items are set.
Unlike vaadin/vaadin-grid#1264, this isn't an issue with the observers so much as it's an issue with properties. When the items change, this function is called:
Changing the size updates the
_effectiveSize
which causes the scroller to rescroll (even if not needed because the first visible index is 0 and it's already scrolled to the top), which causes the iron-list toAfter that, the scroller itself will
Finally, after the size has been set,
_itemsChanged
willSolution?
I imagine that most of the properties and effects that cause a re-render could happen independently of the items changing and truly require a re-render. The grid doesn't know and it's being safe.
However, what the grid could know is whether or not a row's model has changed. If the item (and all of its properties) are the same, and the index/level/expanded/selected/detailsOpened properties have not changed, it's safe to assume that rendering the row again will result in the exact same DOM structure.
Patching
_updateItem()
may also promote gains from other properties or data providers that may be updating the grid and cause it to think it needs to re-render a row when it really doesn't.Live Demo
https://github.com/asyncLiz/vaadin-grid-perf
Steps to reproduce
npm start
Potential solution:
Browsers Affected