ng6-golden-layout icon indicating copy to clipboard operation
ng6-golden-layout copied to clipboard

performance issue

Open esoni88 opened this issue 7 years ago • 6 comments

Hi All, if i open many dialogs i have a performance issue due too many change detection. Why on init in golden layout component of your lib you use this code

....

this.appref.tick = (): void => {
  for (const ar of (this.topWindow as any).__apprefs) {
    ar._zone.run(() => ar.__tick());
  }
};

in this way for a tick in child window is performed tick on other child windows and also in root. can you explain better ? thanks

esoni88 avatar Jan 05 '19 14:01 esoni88

i think it is a better solution :

public ngOnInit(): void {

const anyWin = this.topWindow as any;
if (!this.isChildWindow) {
  anyWin.__apprefs = [];
  anyWin.__injector = this.injector;
  anyWin.__rootRef = this.appref;
}

// attach the application reference to the root window, save the original 'tick' method
anyWin.__apprefs.push(this.appref);
(this.appref as any).__tick = this.appref.tick;

this.appref.tick = (): void => {
  if (!this.isChildWindow) {
    (this.appref as any).__tick();
  } else {
    (this.appref as any).__tick();
    anyWin.__rootRef._zone.run(() => anyWin.__rootRef.__tick());

  }

};

}

in this way for child window tick : in only execute tick on parent and on that window and not on all window opened

esoni88 avatar Jan 05 '19 15:01 esoni88

That's a fairly complex topic. In my use case, we have state shared between all windows, so the change detection needs to be run in all windows simultaneously.

Also note that this largely depends on your state management pattern, we use a redux-like pattern with OnPush change detection in most components, so performance isn't that much impacted for us.

Maybe a solution is to add a switch which changes this behavior between the original solution and the one you found.

martin31821 avatar Jan 20 '19 16:01 martin31821

@dario-frongillo in the latest commit, I refactored the tick procedure to be contained in a service, if you still have this problem, we might be able to add a flag changing the change detection propagation between the windows now.

martin31821 avatar Sep 08 '19 08:09 martin31821

@martin31821 Can you please link the commit change ?

esoni88 avatar Sep 08 '19 09:09 esoni88

There you go: https://github.com/EmbeddedEnterprises/ng6-golden-layout/commit/83fbd30079db6138f94eedaed5add5ed1a476ec7

martin31821 avatar Sep 08 '19 10:09 martin31821

@dario-frongillo is this still a problem or did you get around the issue?

martin31821 avatar May 18 '20 17:05 martin31821