Repository navigation
refactor: avoid unnecessary render cycles in the data provider callback - #5647
Conversation
| this._cache.updateSize(); | ||
| this._effectiveSize = this._cache.effectiveSize; |
There was a problem hiding this comment.
Moving the cache and effective size update outside the debouncer is the primary change here.
They were previously updated inside the flushing debouncer so any following update resulting from the size update actually caused yet another debouncer to get scheduled (and synchronously flushed). This caused a lot of unnecessary content updates, which affected rendering performance negatively.
| if (this._isExpanded(item) && currentItems.indexOf(item) > -1) { | ||
| // Force synchronous data request for expanded item sub-cache | ||
| cache.ensureSubCacheForScaledIndex(itemIndex); |
There was a problem hiding this comment.
This logic is no longer necessary since a similar (but improved) check was added below.
| it('should set itemHasChildren path by default', () => { | ||
| expect(grid.itemHasChildrenPath).to.equal('children'); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Moved this to the main level since I needed to assign a non-default value to to itemHasChildrenPath in beforeEach
|
Kudos, SonarCloud Quality Gate passed!
|
| this._effectiveSize = this._cache.effectiveSize; | ||
|
|
||
| // After updating the cache, check if some of the expanded items should have sub-caches loaded | ||
| this._getVisibleRows().forEach((row) => { |
There was a problem hiding this comment.
Digging into this further, it seems the grid has an _effectiveSize observer that basically does the same. It requests items by calling virtualizer.update() => grid._getItem(...) => cache.ensureSubCacheForScaledIndex(...):
The observer's body is executed when this._hasData is true which is almost always the case except after you have cleared the cache. So, this ensureSubCacheForScaledIndex should be already invoked there.
Although, whether the observer is executed or not also depends on the presence of columnTree. Perhaps that one can be unavailable at the moment the data callback is resolving.
There was a problem hiding this comment.
👍 Thx, I'll see if there's room for improvement there also








Description
This change improves how a data provider callback is processed in
vaadin-grid-data-provider-mixin. It makes sure that the cache gets fully updated with all synchronously available data before actually rendering the grid rows. The updated data provider causes significantly fewer row rendering cycles when hierarchical data is applied to the grid.This will be followed by a related PR to
flow-component.Type of change
Performance enhancement