This repository was archived by the owner on Jan 6, 2025. It is now read-only.
Possible performance issue with double forced reflow #761
Labels
has pr
A PR has been created to address this issue
P3
Important issue that needs to be resolved
performance
Milestone
Bug, feature request, or proposal:
Bug/performance proposal
What is the expected behavior?
Not having two forced reflows on directive initialisation
What is the current behaviour?
Two (or more) forced reflows on directive initialisation
What are the steps to reproduce?
One example is in the
fxLayoutDirective
. You can see the_updateWithDirection
being called inside thengOnChanges
and after that in thengOnInit
.I might be wrong, but from what I can tell from the profiler this calls the heavy
_updateWithDirection
twice on initalisation. Because you initialise the directive by using thelayout
input, it will always go through thengOnChanges
hook anyways. Which makes this line obsolete, or better yet, causing unnecessary recalculations.I noticed in the profiler that these updates are pretty intensive for the cpu, by causing forced reflows
Other examples:
FlexAlignDirective._updateWithValue
FlexOrderDirective._updateWithValue
FlexDirective._updateStyle
FlexLayoutAlignDirective._updateWithValue
Instead of removing the corresponding lines, you could also check inside the
ngOnChanges
if thengOnInit
hook has already ran. And if so, execute the function. This needs to be done for theLayoutGapDirective
anyways, because it needs to be executed inside thengAfterViewInit
.Another thing that I noticed is the cpu hungry
_getDisplayStyle
inside every directive that extends theBaseDirective
. If the current element does not use the media queries.xs, .xl ...
, how necessary is this call?What is the use-case or motivation for changing an existing behaviour?
To have a faster flex framework
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
All
Is there anything else we should know?
Like I said, my assumptions might be wrong, and there is actually a valid reason for executing it twice.
The text was updated successfully, but these errors were encountered: