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

bug(table): Performance issue when paginator is set on AfterViewInit #29759

Open
1 task
martinboue opened this issue Sep 18, 2024 · 0 comments
Open
1 task
Labels
area: material/table needs investigation A member of the team needs to do further investigation to determine the root cause P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent perf This issue is related to performance

Comments

@martinboue
Copy link

martinboue commented Sep 18, 2024

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

According to documentation the recommended way of setting up a table with paginator is by doing this:

@ViewChild(MatPaginator) paginator: MatPaginator;
dataSource: MatTableDataSource<T>;

ngOnInit(): void {
   this.dataSource.data = this.getMillionsOfRows();
}

ngAfterViewInit() {
   this.dataSource.paginator = this.paginator;
}

But because no paginator is defined until view is initialized, the whole table will be rendered the first time which can cause a significant performance issue.

In my case real-case project, I'm experiencing ~750ms to render 600 elements in a 8 columns table, and ~80 ms with workaround n°2.

Workarounds

  1. Use @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; and set paginator to dataSource on init.
    => Does not work if paginator is in a conditional block (@if for example)
  2. or, Set data to dataSource after view init.
    => Not great, the table will be rendered empty at first.

Reproduction

Stackblitz link: https://material.angular.io/components/table/examples#table-overview
Steps to reproduce:

  1. Open Material example in Stackblitz
  2. Edit table-overview-example.ts and add the following method to the component:
test() {
   console.log('test');
}
  1. Edit table-overview-example.html and change the first <td> tag to:
<td mat-cell *matCellDef="let row"> {{ test() }} {{row.id}} </td>
  1. Open browser the console and refresh the view

Expected Behavior

5 logs, i.e. the page size.

Actual Behavior

100 logs, i.e. the total number of elements.

Environment

  • Angular: >18
  • CDK/Material: >18
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows
@martinboue martinboue added the needs triage This issue needs to be triaged by the team label Sep 18, 2024
@wagnermaciel wagnermaciel added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent perf This issue is related to performance needs investigation A member of the team needs to do further investigation to determine the root cause area: material/table and removed needs triage This issue needs to be triaged by the team labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/table needs investigation A member of the team needs to do further investigation to determine the root cause P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent perf This issue is related to performance
Projects
None yet
Development

No branches or pull requests

2 participants