Answer the question
In order to leave comments, you need to log in
Why is Angular 5 very slow?
I'm trying to speed up an Angular application.
The algorithm is as follows:
There is a root component in which child components are displayed in the router-outlet. Orders are displayed on the child component by default. Order click event - (click)="orderClick(order)"
Some work is done in the orderClick function and then the order editor service function is called this.editor.getShow(...);
In the getShow function some work is done and called
This code makes the order editor a child component. For the purity of the experiment, it is empty and contains only ngAfterContentInit and ngAfterViewInit, inside of which there is only console.time. Problemthis.router.navigate(['\ordereditor']);
is that the service functions take an unreasonably long time. Within each function, console.time is set on entry and exit. Before calling this.router.navigate and the first line in the constructor of the component that is also called console.time. In ngAfterContentInit and ngAfterViewInit look like this
ngAfterContentInit() {
console.timeEnd("constructor"); // Для измерения задержки между созданием конструктора и переходом сюда
console.time("ngAfterContentInit");
setTimeout(() => {
console.timeEnd("ngAfterContentInit");
},
0);
}
ngAfterViewInit() {
console.time("ngAfterViewInit");
setTimeout(() => {
console.timeEnd("ngAfterViewInit");
console.timeEnd("total time"); // Полное время - от начала клика и до этого места
},
0);
}
click: 0.165771484375ms
get show: 15.595947265625ms
navigate: 49.48779296875ms
constructor: 14.7900390625ms
[Violation] 'click' handler took 160ms
ngAfterContentInit: 130.77294921875ms
ngAfterViewInit: 126.493896484375ms
total time: 287.324951171875ms
ng build --prod --output-hashing=none
Answer the question
In order to leave comments, you need to log in
here is a checklist with tips on speeding up angular
here is a good report in Russian on speeding up angular applications
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question