Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve datagrid performance #394

Merged
merged 25 commits into from Sep 22, 2022
Merged

Conversation

martinRenou
Copy link
Member

@martinRenou martinRenou commented Sep 7, 2022

cc. @ibdafna

This PR improves the performance of the grid by reworking the drawing of merged cells logic.

  • Before (resizing/scrolling a 1M cells grid with merged cells freezes):
before.mp4
  • After (resizing/scrolling a 1M cells grid with merged cells works smoothly):
after.mp4

Note for the tester: You will see a big difference in performance if you zoom out a lot and show a lot of cells.

@martinRenou martinRenou added the performance Addresses performance label Sep 7, 2022
@blink1073 blink1073 added the enhancement New feature or request label Sep 7, 2022
@afshin afshin changed the title Improve datagrid performances Improve datagrid performance Sep 7, 2022
@@ -2146,7 +2144,7 @@ export class DataGrid extends Widget {
}

// Test whether there is content to blit.
let needBlit = curH > 0 && curH > 0 && width > 0 && height > 0;
let needBlit = curW > 0 && curH > 0 && width > 0 && height > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵️ 🔍 🐜

@martinRenou
Copy link
Member Author

This is the diff for the API:

diff --git a/review/api/datagrid.api.md b/review/api/datagrid.api.md
index 9197a504..ebd1c1c3 100644
--- a/review/api/datagrid.api.md
+++ b/review/api/datagrid.api.md
@@ -131,16 +131,11 @@ export interface CellGroup {
 export namespace CellGroup {
     export function areCellGroupsIntersecting(group1: CellGroup, group2: CellGroup): boolean;
     export function areCellGroupsIntersectingAtAxis(group1: CellGroup, group2: CellGroup, axis: 'row' | 'column'): boolean;
-    // (undocumented)
-    export function areCellsMerged(dataModel: DataModel, rgn: DataModel.CellRegion, cell1: number[], cell2: number[]): boolean;
-    export function calculateMergeOffsets(dataModel: DataModel, regions: DataModel.CellRegion[], axis: 'row' | 'column', sectionList: SectionList, index: number): [number, number, CellGroup];
     export function getCellGroupsAtColumn(dataModel: DataModel, rgn: DataModel.CellRegion, column: number): CellGroup[];
     export function getCellGroupsAtRegion(dataModel: DataModel, rgn: DataModel.CellRegion): CellGroup[];
     export function getCellGroupsAtRow(dataModel: DataModel, rgn: DataModel.CellRegion, row: number): CellGroup[];
     export function getGroup(dataModel: DataModel, rgn: DataModel.CellRegion, row: number, column: number): CellGroup | null;
     export function getGroupIndex(dataModel: DataModel, rgn: DataModel.CellRegion, row: number, column: number): number;
-    export function isCellGroupAbove(group1: CellGroup, group2: CellGroup): boolean;
-    export function isCellGroupBelow(group1: CellGroup, group2: CellGroup): boolean;
     export function joinCellGroups(groups: CellGroup[]): CellGroup;
     export function joinCellGroupsIntersectingAtAxis(dataModel: DataModel, regions: DataModel.CellRegion[], axis: 'row' | 'column', group: CellGroup): CellGroup;
     export function joinCellGroupWithMergedCellGroups(dataModel: DataModel, group: CellGroup, region: DataModel.CellRegion): CellGroup;

@afshin @blink1073 do you think that's a problem? I can add those back and add a DeprecationWarning if that helps the PR get merged.

@martinRenou
Copy link
Member Author

A bi-product of this PR is that it fixes a rendering issue when shrinking cells that are at the same level as a merged cell:

  • Before:
before_issue.mp4
  • After:
after_issue.mp4

@blink1073
Copy link
Member

Removing them seems reasonable to me since datagrid is still pre-1.0.

@martinRenou
Copy link
Member Author

Removing them seems reasonable to me since datagrid is still pre-1.0.

Thanks for your answer! I updated the API file

@martinRenou martinRenou marked this pull request as ready for review September 7, 2022 15:04
Copy link
Member

@afshin afshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work tracking down the performance issue and resolving it, @martinRenou!

I think we can merge this and iterate because:

  • This is a pre-1.0 package (although, perhaps we should consider jumping straight to 2.0 to be in line with the rest of the library)
  • @lumino/datagrid is downstream of the other packages

But we should make sure that before the final version we address:

  • refactoring with a type PaintRegion
  • implementing and removing the TODO messages
  • potentially de-duplicating the slightly different but very similar loops

@martinRenou
Copy link
Member Author

But we should make sure that before the final version we address:

  • refactoring with a type PaintRegion
  • implementing and removing the TODO messages
  • potentially de-duplicating the slightly different but very similar loops

Definitely 👍🏽

Maybe @ibdafna would like to give this a try before we merge? As he implemented the merge cells logic and knows what to test etc to make sure everything works nicely.

@ibdafna
Copy link
Member

ibdafna commented Sep 9, 2022 via email

@ibdafna
Copy link
Member

ibdafna commented Sep 11, 2022

127.0.0.1_8080.and.1.more.page.-.Personal.-.Microsoft.Edge.2022-09-11.08-23-26.mp4

@martinRenou I see some issues with border rendering when scrolling x/y axes (video attached)

@martinRenou
Copy link
Member Author

Thanks for trying! I haven't seen those. I will try to replicate.

@martinRenou
Copy link
Member Author

I can indeed replicate in the base example (the issue was not appearing in my custom grid for some reason).

I will investigate :)

@martinRenou
Copy link
Member Author

martinRenou commented Sep 19, 2022

@ibdafna the latest commit fc7acd4 is fixing the issue you mention above :)

scroll.mp4

EDIT: Looking at my screencast I now see an issue with the column header C 0, 4 which is not visible (I can reproduce the issue and working on it)

@martinRenou
Copy link
Member Author

Looking at my screencast I now see an issue with the column header C 0, 4 which is not visible (I can reproduce the issue and working on it)

This is fixed by 32952d7. The issue was that I was taking into account the x-scroll level for the column header and the y-scroll level for the row header while this should not be the case (headers are sticky, not following the scroll).

@martinRenou
Copy link
Member Author

@afshin @ibdafna this is ready for another review :)

@ibdafna
Copy link
Member

ibdafna commented Sep 19, 2022

LGTM! Let's ship it!! ♥💘💖💗💓💙💚💛❤🖤🧡💜

It appears that when slowly scrolling merged cells, the area considered
"clean" is actually not really clean if a merged group is intersected by
that area. Redrawing those groups fixes it.
@martinRenou
Copy link
Member Author

Thanks!! I actually found another issue when slowly scrolling. 830e094 seems to fix that issue.

potentially de-duplicating the slightly different but very similar loops

The improvement suggested by @afshin gets more urgent to fix as it's now 6 loops that are quite similar, but I can do it in a separate PR if that's fine.

@ibdafna
Copy link
Member

ibdafna commented Sep 21, 2022

I'd love to see this released this week 😻

Copy link
Member

@afshin afshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🚀

@afshin afshin merged commit ebaefcc into jupyterlab:main Sep 22, 2022
@martinRenou martinRenou deleted the explore_datagrid_perf branch September 23, 2022 07:27
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request performance Addresses performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants