Repository navigation
perf(docs-infra): remove usage of the NgClass directive - #48312
pkozlowski-opensource wants to merge 1 commit into
Conversation
|
You can preview 5419936 at https://pr48312-5419936.ngbuilds.io/. |
5419936 to
5f44a33
Compare
|
You can preview 5419936 at https://pr48312-5419936.ngbuilds.io/. |
5f44a33 to
a735499
Compare
|
You can preview a735499 at https://pr48312-a735499.ngbuilds.io/. |
a735499 to
3d7f012
Compare
|
You can preview 3d7f012 at https://pr48312-3d7f012.ngbuilds.io/. |
3d7f012 to
494f1d0
Compare
|
You can preview 494f1d0 at https://pr48312-494f1d0.ngbuilds.io/. |
NgClass has non-negligable performance cost, especially if a different object is provided as NgClass input (which was the case for the NavItemComponent). The perfornace problem was noticed in the scope of the INP score investigations while profiling the https://angular.io/resources page. On this particular page replacing NgClass usage with alternatives results in 20x (!) runtime perf improvement. Such big improvement is possible since we avoid unneeded CSS classes removal / adding in the DOM. Part of angular#25518
494f1d0 to
692618e
Compare
|
You can preview 692618e at https://pr48312-692618e.ngbuilds.io/. |
josephperrott
left a comment
There was a problem hiding this comment.
I have the one comment about a potential anti-pattern, but if I am wrong/we want to go with it then its good to go.
| @@ -1,25 +1,25 @@ | |||
| <div *ngIf="!node.children"> | |||
| <a href="{{node.url}}" [ngClass]="classes" title="{{node.tooltip}}" | |||
| <a href="{{node.url}}" [class]="classes" title="{{node.tooltip}}" | |||
There was a problem hiding this comment.
If I remember correctly we typically consider having a binding on [class] as an antipattern, as opposed to the specific class.member item. This makes it so that if another directive is involved that affects classes it gets clobbered.
There was a problem hiding this comment.
As of ivy we do merge class bindings from different sources so the clobbering is no longer the issues. I was considering using individual class.xyz bindings, but:
- we do need to have "calculated" name (level-x) anyway;
- the same set of classes is bound in 3 different places in this template so it would be more code duplication.
I see the current approach as the "least bad"...
|
This PR was merged into the repository by commit 6706fab. |
NgClass has non-negligable performance cost, especially if a different object is provided as NgClass input (which was the case for the NavItemComponent). The perfornace problem was noticed in the scope of the INP score investigations while profiling the https://angular.io/resources page. On this particular page replacing NgClass usage with alternatives results in 20x (!) runtime perf improvement. Such big improvement is possible since we avoid unneeded CSS classes removal / adding in the DOM. Part of #25518 PR Close #48312
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
NgClass has non-negligable performance cost, especially if a different object is provided as NgClass input (which was the case for the NavItemComponent). The perfornace problem was noticed in the scope of the INP score investigations while profiling the https://angular.io/resources page. On this particular page replacing NgClass usage with alternatives results in 20x (!) runtime perf improvement. Such big improvement is possible since we avoid unneeded CSS classes removal / adding in the DOM. Part of angular#25518 PR Close angular#48312
NgClass has non-negligable performance cost, especially if a
different object is provided as NgClass input (which was the case
for the NavItemComponent). The perfornace problem was noticed
in the scope of the INP score investigations while profiling the
https://angular.io/resources page. On this particular page replacing
NgClass usage with alternatives results in 20x (!) runtime perf
improvement. Such big improvement is possible since we avoid unneeded
CSS classes removal / adding in the DOM.
Part of #25518
Before:

By removing calls to

ngClasscalls that suffer from the problem described here (see experiment in #48312) we are seeing 20x spped improvement (the rendering time goes down to ~16ms):