Skip to content

perf: improve grid column group auto-width performance - #5122

Merged
web-padawan merged 2 commits into
masterfrom
perf/improve_grid_column_group_auto_width_performance
Dec 16, 2022
Merged

web-padawan merged 2 commits into
masterfrom
perf/improve_grid_column_group_auto_width_performance

Conversation

@sissbruecker

@sissbruecker sissbruecker commented Dec 16, 2022 •

Copy link
Copy Markdown
Member

Description

When using auto-size in combination with column groups the performance of the grid decreases significantly. The reason for that is that __getDistributedWidth runs __getIntrinsicWidth several times for nested columns when measuring a group:

const sumOfWidthOfAllChildColumns = columnGroup._visibleChildColumns
.map((col) => this.__getIntrinsicWidth(col))
.reduce((sum, curr) => sum + curr, 0);

const proportionOfExtraSpace = this.__getIntrinsicWidth(innerColumn) / sumOfWidthOfAllChildColumns;
const shareOfInnerColumnFromNecessaryExtraSpace = proportionOfExtraSpace * extraNecessarySpaceForGridColumnGroup;
return this.__getIntrinsicWidth(innerColumn) + shareOfInnerColumnFromNecessaryExtraSpace;

This change adds a cache that gets populated with the intrinsic width of columns after they have been measured, so that they don't need to be measured again. The cache is reset when recalculateColumnWidths is called again.

Testing this with the grid benchmark tests in flow-components, using 50 columns, 10 groups, results in the following rendering times (avg of 20 measurements):

  • without cache: 636ms
  • with cache: 253ms

The logic could probably also be rewritten to do measurement in multiple phases, however this solution seems like a reasonable alternative in the meanwhile.

Type of change

  • Performance improvement

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@sissbruecker
sissbruecker marked this pull request as ready for review December 16, 2022 13:16
@web-padawan
web-padawan merged commit 32fa7ff into master Dec 16, 2022
@web-padawan
web-padawan deleted the perf/improve_grid_column_group_auto_width_performance branch December 16, 2022 16:54
web-padawan pushed a commit that referenced this pull request Dec 16, 2022
…5125)

Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.0.0.alpha7 and is also targeting the upcoming stable 24.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants