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

Notebook slow scrolling caused by update layer tree #126880

Closed
Tracked by #7360
rebornix opened this issue Jun 22, 2021 · 12 comments
Closed
Tracked by #7360

Notebook slow scrolling caused by update layer tree #126880

rebornix opened this issue Jun 22, 2021 · 12 comments
Assignees
Labels
debt Code quality issues freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues notebook-layout polish Cleanup and polish issue
Milestone

Comments

@rebornix
Copy link
Member

Originally reported by @digitarald

image

Expensive layout is the cuplrit, even warned as layout shift so content really seems to move on every frame while scrolling – cased by a wheel event handler calling setScrollPositionNow.

After digging into the perf log, it seems there is a long update layer tree (~10ms) for every scroll.

@rebornix rebornix self-assigned this Jun 22, 2021
@rebornix rebornix added notebook-layout freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues labels Jun 22, 2021
@rebornix
Copy link
Member Author

@digitarald can you try below when you get a chance to reproduce the issue

  • run vscode with --disable-gpu and see if you can reproduce
  • check if you have a large code cell (with a lot of lines), if so, try to split the cell to smaller cells and see if you still see the slowness

@claudiaregio
Copy link

claudiaregio commented Jul 2, 2021

+1
image

@claudiaregio
Copy link

+1
image

@alceballosa
Copy link

Hi @claudiaregio , I tried making a new notebook (using the disable-gpu flag) with only a few cells of code and one markdown cell, and the behavior is the same. Are there any other options I can test? To me it seems that it's not slow at all, only that the sensitivity of the mouse scroll goes up for those cells.

Thank you!

@rebornix
Copy link
Member Author

@alceballosa do you have editor.mouseWheelScrollSensitivity for the text editor?

@alceballosa
Copy link

Hi @rebornix , that's right.

@rebornix rebornix modified the milestones: July 2021, August 2021 Jul 28, 2021
@rebornix rebornix modified the milestones: August 2021, September 2021 Aug 22, 2021
rebornix added a commit that referenced this issue Sep 10, 2021
rebornix added a commit that referenced this issue Sep 11, 2021
utajum pushed a commit to utajum/vscode that referenced this issue Sep 13, 2021
@rebornix
Copy link
Member Author

rebornix commented Sep 15, 2021

Did quite some experiments with scrolling last week, there are multiple ways to reduce the creation time of a cell or reducing the browser rendering time. Having all the experiments doesn't necessarily lead to better perceived user experience so we would need to fine tune each improvement and cherry-pick them to main branch one by one. The experiments and findings:

  • Fewer operations on cell view init creation
    • We used to register event listeners on cell view model. It will trigger false event listener mem leak alert (which prints call stack) and cause significant slow down. Better way to handle this is registering a single listener on NotebookViewModel and then redirect the events to each cell.
  • Reduce forced layout
    • Previously when we render a cell output, we always check its offsetHeight first and then register a resize observer on the DOM element. The offsetHeight check is used to generate an init height but it's actually not necessary as resize observer can help with that can avoid forced layout by a ton. It does lead to a layout change on each cell but it's better than forced reflow.
    • If we receive the height change from resize observer before the list view's dynamic height check, we can probably populate the new height to list view other than relayout the cell in next frame
  • Reduced layout shift
  • Reduce monaco editor creation
    • Instead of caching monaco editors on list view templates, we can have a dedicated DOM for all monaco editors and reuse them on cell rendering.
  • Move costly operations to web worker
    • When model changes, we will recalculate outline, which is currently computed in main thread, it will block the UI when the document is large.

Perf log before and after the experiments

image

@roblourens
Copy link
Member

I don't understand how the resize observer avoids a forced layout, wouldn't it have to do that to know the size? Is the benefit just that we get to delay that a little bit?

@rebornix
Copy link
Member Author

I don't understand how the resize observer avoids a forced layout, wouldn't it have to do that to know the size? Is the benefit just that we get to delay that a little bit?

The resize observer doesn't avoid forced layout, but stop checking offsetHeight does. The assumption here is resize observer will give us the init height.

@rebornix
Copy link
Member Author

Reduced forced reflow after changes in #133571

image

image

@rebornix rebornix modified the milestones: September 2021, On Deck Sep 29, 2021
@rebornix rebornix added polish Cleanup and polish issue debt Code quality issues labels Oct 11, 2021
@rebornix rebornix removed the notebook label Oct 21, 2021
@rebornix
Copy link
Member Author

Let's continue the following work in #117644

@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues notebook-layout polish Cleanup and polish issue
Projects
None yet
Development

No branches or pull requests

6 participants
@roblourens @rebornix @kieferrm @claudiaregio @alceballosa and others