I have a component, that "lazy loads" some comments, at the interval of 100ms.
When I use setTimeout, it is really laggy.
component
<div *ngFor="let post of posts">
<app-post [post]="post" ></app-post>
</div>
This makes my Application laggy (avg fps 14, idle time 51100ms):
while(this.postService.hasPosts()){
setTimeout(()=> {
this.posts.push(this.postService.next(10));
},100);
}
This make my Application smooth (avg fps 35, idle time 40800ms)
while(this.postService.hasPosts()){
timer(100).subscribe(()=> {
this.posts.push(this.postService.next(10));
});
}
Is there any explaination, why the rxjs timer, works that much better ?
I did a runtime analysis with firefox. In the first example, the frame rate drops to 14 fps In the other example, 35 fps.
Even the idle time is 20% lower.
This method is even smoother (avg fps 45, idle time 13500ms):
interval(100).pipe(takeWhile(this.postService.hasPosts()).subscribe(()=> {
this.posts.push(this.postService.next(10));
});
}
