According to the Angular documentation
Filtering and sorting operations can be resource-intensive. When Angular invokes these pipe methods frequently, it can lead to a degraded user experience, especially with even moderately-sized lists. Misuse of filter and orderBy in AngularJS apps has resulted in complaints about the performance of Angular itself.
I initially implemented filter, order, and search pipes in my application and didn't face any performance issues. However, lately, they have started causing some problems.
In my application, I have something similar to this setup:
component.html
<ul>
<li *ngFor="let user of users | filter: filters | order: order | search: searchTerm"></li>
</ul>
component.ts
users = [
{
firstName: "Steve",
lastName: "Smith",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff8b9a8c8bbf8b9a8c8bd19c9092">[email protected]</a>",
id: 102,
tags: [
'newUser',
'important',
'funny'
]
},
// More user data...
];
While the current implementation is functional, I understand that it may not be performing optimally.
The respective filter.pipe.ts and order.pipe.ts files contain logic for filtering and ordering users based on various criteria, which is currently being applied as chained pipes.
My plan is to refactor these pipes into functions, but I am unsure about the best way to chain them effectively while maintaining the same functionality.
One approach I'm considering involves chaining the functions like this:
private USERS: Users = [ ... ];
public users: Users;
this.users = this.search(this.order(this.filter(this.USERS, filters), order), searchTerm);
Is this method the most efficient solution?