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.

Possible performance issue with double forced reflow

See original GitHub issue

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 the ngOnChanges and after that in the ngOnInit.

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 the layout input, it will always go through the ngOnChanges 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 the ngOnInit hook has already ran. And if so, execute the function. This needs to be done for the LayoutGapDirective anyways, because it needs to be executed inside the ngAfterViewInit.

Another thing that I noticed is the cpu hungry _getDisplayStyle inside every directive that extends the BaseDirective. 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.

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
PierreDuccommented, Jul 31, 2018

Nice, just an easy benchmark shows that the flex-layout library is now 75% faster 👍

1reaction
CaerusKarucommented, Jun 18, 2018

Excellent suggestion, it’s been moved in the latest commit on the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a Forced Reflow and How to Solve it? - Yonatan Kra
Force reflow (or Layout Reflow) is a major performance bottleneck. It happens when a measurement of the DOM happens after a DOM mutation....
Read more >
AngularJS Forced reflow is a likely performance bottleneck ...
Google Chrome developer tools Timeline data suggests that Forced reflow is a likely performance bottleneck. is the problem.
Read more >
Double Reflow-Induced Brittle Interfacial Failures in Pb-free ...
A preliminary failure analysis of Component A at the factory suggested poor adhesion of the ball to the substrate, with possible inner row...
Read more >
Forced Reflow Is A Likely Performance Bottleneck - Morris.Js
Force reflow or Layout Reflow is a major performance bottleneck. It happens when a measurement of the DOM happens after a DOM mutation....
Read more >
Preventing Forced Reflows with Strategic JavaScript II
Simply moving that code outside the <div> creation loop was not sufficient to cure the forced reflow; it's the mixing of measurement and ......
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