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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

elements: no coalescing of change detection invocations across instances #33060

Open
gkalpak opened this issue Oct 9, 2019 · 3 comments
Open
Labels
area: elements Issues related to Angular Elements area: performance P4 A relatively minor issue that is not relevant to core functions state: confirmed type: bug/fix
Milestone

Comments

@gkalpak
Copy link
Member

gkalpak commented Oct 9, 2019

馃悶 bug report

Affected Package

The issue is caused by package @angular/elements.

Is this a regression?

No.

Description

While Angular custom elements do coalesce change detection invocations per element instance (see scheduleDetectChanges()), there is no coalescing across other instances of the same element or other elements (even for those on the same injector or component tree.

This results in too many CDs on pages/routes with many custom elements and can negatively affect performance. (This is the case for example in https://angular.io/guide/router, which has ~200 custom elements.)

Anything else relevant?

Related issues: #23813, #33059

EDIT:
Similar issue with useful context (closed in favor of this one): #23813
PR (that would at least cover some usecases): #23885

@pkozlowski-opensource
Copy link
Member

This is a confirmed issues with elements <-> change detection interaction. On the mentioned page we are getting the following picture under the profiler (the highlighted task of ~400ms is showing the issue):

Screen Shot 2020-05-29 at 14 15 27

@gkalpak
Copy link
Member Author

gkalpak commented May 29, 2020

Similar issue with useful context (closed in favor of this one): #23813
PR (that would at least cover some usecases): #23885

@dbaranovsky97
Copy link

We also faced this problem. The components initialization time grows in a parabola along with the growth of the number of components:
ng-vs-webng
Here is a testbed where you can see it - https://stackblitz.com/edit/angular-nn5ec8
I also wrote a custom strategy there - https://stackblitz.com/edit/angular-nn5ec8?file=src/element-strategy/component-factory-custom-strategy.ts . There I redesigned the scheduler so that it runs all tasks in one requestAnimationFrame. This greatly improved performance (although it is still worse than in regular angular components):
image
Perhaps you should use the same approach in the default strategy? If it's ok, I can make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: elements Issues related to Angular Elements area: performance P4 A relatively minor issue that is not relevant to core functions state: confirmed type: bug/fix
Projects
None yet
Development

No branches or pull requests

5 participants