angular-tree-component icon indicating copy to clipboard operation
angular-tree-component copied to clipboard

Change tracking causes high cpu usage

Open joekaiser opened this issue 9 years ago • 4 comments

We have a small tree. ~30 nodes in total. I noticed the page was starting to get sluggish and Chrome's internal task manager said it was using 93% CPU. I ran the profiler in chrome to see what JS was causing problems and saw that the detect changes process is running quite often.

At first I thought I was doing something, but after spending 2 days combing over the code base, I am fairly certain I am not. My use case is this.

  • load the tree on page load. Each child node looks like { modelId: nodeId, name: nodeName, path: nodePage }

  • I listen to the onActivate event from the tree and use that to get the path from the nodes data. I then fetch a URL and that is it.

    nodeActivated(){ let selectedPath = $event.node.data.path; this.modelService.getRules(selectedPath).subscribe(res=>this.currentRules = res); }

Once the tree is loaded, I am not modifying the nodes. Is there a way I can turn off the change detection so I can verify if my assumption is correct?

edit I know NG2 has the ChangeDetectionStrategry I could use. I guess I am wondering If the tree has some kind of built in mechanism I can override

(originally using 3.4.0, but still persists after upgrading to 3.6.0)

image

joekaiser avatar May 12 '17 15:05 joekaiser

Hey, Can you check if it improves substantially when using enableProdMode()? Just so I know how grave this problem is.

One of my intentions down the road is to supply 2 different modules - one that is based on OnPush strategy, which is good for immutable / observable data, and one that is based on Default strategy, which is good for data binding.

adamkleingit avatar May 20 '17 15:05 adamkleingit

I get the same behavior

joekaiser avatar May 22 '17 14:05 joekaiser

Are there any news about the OnPush Edition of this component?

CC84 avatar Dec 28 '17 10:12 CC84

I think having 2 modules will make the maintenance too complicated. You can always wrap the tree with an onPush component

adamkleingit avatar Jul 13 '18 07:07 adamkleingit