P-treetable performance issue with re-rendering p-treeTableCheckbox / p-checkbox
Describe the bug
I have a performance issue after upgrading PrimeNG from v17.18.9 to v19.0.10 with the p-treeTable component. I have a column which has inside p-treeTableCheckbox. The values for the checkbox are coming from a backend request on GET, constructed and set to the respective TreeNode and visualised with the respective checked/unchecked/partially checked type. Besides the standard expand/collapse buttons on each row ( I have 3 levels of nesting at most), I have expand/collapse all button in the header which recursively expands or collapses all nodes. Without any changes to the code, simply upgrading the PrimeNG version, broke the performance of the table entirely. When I click on expand/expand all, the component is re-rendered too many times which slows it down and makes it unusable. The state of the checkboxes lags and they took 1.5-2 seconds to appear. If the checkboxes are disabled, they are not initially rendered as disabled and the user can click on them. When I add a console.log to ngAfterViewChecked, the component is rendered 3 times with PrimeNG 17 and 1660 with PrimeNG v19. I remade the component with the new implementation of selectionKeys and there is no change in the performance.
Pull Request Link
No response
Reason for not contributing a PR
- [ ] Lack of time
- [x] Unsure how to implement the fix/feature
- [ ] Difficulty understanding the codebase
- [ ] Other
Other Reason
No response
Reproducer
https://stackblitz.com/edit/edtx2kip-lxmjutyx?file=src%2Fapp%2Ftree-table-selection-checkbox-demo.ts,src%2Fapp%2Ftree-table-selection-checkbox-demo.html,src%2Fservice%2Fnodeservice.ts
Environment
"dependencies": { "@angular-architects/module-federation": "19.0.3", "@angular/animations": "19.2.2", "@angular/common": "19.2.2", "@angular/compiler": "19.2.2", "@angular/core": "19.2.2", "@angular/forms": "19.2.2", "@angular/material": "19.2.3", "@angular/platform-browser": "19.2.2", "@angular/platform-browser-dynamic": "19.2.2", "@angular/router": "19.2.2", "@ngrx/effects": "19.0.1", "@ngrx/operators": "19.0.1", "@ngrx/store": "19.0.1", "@ngrx/store-devtools": "19.0.1", "@ngx-translate/core": "16.0.4", "@ngx-translate/http-loader": "16.0.1", "cp-lht-spinner": "0.0.21", "ng-openapi-gen": "0.52.0", "primeicons": "7.0.0", "primeng": "19.0.10", "rxjs": "7.8.2", "tslib": "2.8.1", "zone.js": "0.15.0" }, "devDependencies": { "@angular-devkit/build-angular": "19.2.3", "@angular/cli": "19.2.3", "@angular/compiler-cli": "19.2.2", "@types/jasmine": "5.1.7", "@typescript-eslint/eslint-plugin": "8.26.1", "@typescript-eslint/parser": "8.26.1", "eslint": "9.22.0", "eslint-config-prettier": "10.1.1", "eslint-plugin-prettier": "5.2.3", "jasmine-core": "5.6.0", "karma": "6.4.4", "karma-chrome-launcher": "3.2.0", "karma-coverage": "2.2.1", "karma-jasmine": "5.1.0", "karma-jasmine-html-reporter": "2.1.0", "ngx-build-plus": "19.0.0", "prettier": "3.5.3", "typescript": "5.8.2" }
Angular version
19.2.2
PrimeNG version
v19
Node version
No response
Browser(s)
Chrome Version 134.0.6998.166
Steps to reproduce the behavior
- Expand all nodes
- View the behaviour of the checkboxes
Expected behavior
P-treetable expands/collapses everything without lag
This issue has been automatically marked as stale due to a lack of activity. If this issue is still relevant to you, please leave a comment so we can keep it open. We apologize for not being able to prioritize it sooner. If you have any new information or questions, please share them in your comment!
There is no real fix for this issue, but the following workaround significantly reduces the problem:
- Use ChangeDetectionStrategy.OnPush on the component containing the p-treetable
- Use native HTML inputs/checkboxes inside the tree table instead of PrimeNG input components
From testing, the excessive change detection seems to come specifically from the interaction between p-treetable and nested PrimeNG components. Replacing them with native controls greatly reduces the number of change detection cycles.