question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(cdk/scrolling): CDK performance degrades for large lists

See original GitHub issue

I noticed that using the CDK virtual scroll directive to render large lists (e.g., 1-2M lines) suffers from severe performance degradation. This was surprising because the virtual scroll only renders a handful of lines (that’s the whole point of using virtual scrolling!). After some investigating I noticed that if my component gets the list of items to render as an input parameter, performance degrades. However, if the list of items is defined internally, performance is great.

For example, this gives me great scrolling performance (StackBlitz),

@Component({
  selector: 'long-list',
  template: `
    <cdk-virtual-scroll-viewport itemSize="15">
      <div *cdkVirtualFor="let item of items">{{item}}</div>
    </cdk-virtual-scroll-viewport>`
})
class LongListComponent {
  items: string[] = Array.from({length: 2e6}).map((_, i) => `Item #${i}`);
}

This gives me poor performance (StackBlitz),

@Component({
  selector: 'long-list',
  template: /* Same as above */,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
class LongListComponent {
  @Input() items: string[] = [];
}

@Component({
  selector: 'my-app',
  template: `<long-list [items]="appItems"></long-list>`
})
class MyApp {
  appItems: string[] = Array.from({length: 2e6}).map((_, i) => `Item #${i}`);
}

You’ll see what I mean if you scroll down/up quickly in either example. Of course when the component template is more complex and the view hierarchy is deeper the performance difference is much more pronounced. In my case it makes virtual scroll hardly usable.

Looking at the performance profile, it seems like change detection is kicking in as I scroll and doing processing that apparently scales up along with the size of the list. If that’s true, it means that even modestly long lists are suffering from excessive processing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jelbourncommented, Mar 5, 2021

@mmalerba could you set up some time to pair with Misko on this? I think he would be interested in this use-case and might have some insights on options

0reactions
angular-automatic-lock-bot[bot]commented, Apr 10, 2021

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Virtualize large lists with the Angular CDK - web.dev
When scrolling lists become very long (hundreds, thousands, or hundreds of thousands of items), application performance can suffer.
Read more >
bug(cdk-virtual-scroll): Scrolling fast makes the viewport blank ...
The whole viewport will be blank as long as you scroll. The second viewport uses a bizarre fix and if you try the...
Read more >
Cdk virtual scrolling issue - angular - Stack Overflow
The question has been asked some time ago, but there is a solution which is not a workaround. First you need the Viewport...
Read more >
Create an Infinite Scrolling list with Angular CDK ... - YouTube
Angular #Material #InfiniteScroll #CDKIn this video, I walk you through building a blazing fast infinite scrolling list using the Angular ...
Read more >
Rendering Large Lists in Angular
In this tutorial, we will learn how to render large lists of data in ... we need to import the ScrollingModule from @angular/cdk/scrolling....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found