We spent a lot of time optimizing our code to increase performance of UX of our app. But still we thought it was not up to the mark as it was taking little more time to load UI where as getting the response from API was in less than a second. We felt, some thing was wrong.
We decided to check in a particular page what part of code is taking a lot of time using performance panel from chrome dev tool.
So is it bad to use _.findWhere?
The answer is NO. There is nothing wrong in using _.findWhere, but you also need to know when to not use it.
Suppose you have a array of objects, lets say “example_array”, you want to find a particular object in that array only once. Then using _.findWhere is good.
But you have a scenario where you want to find different objects from “example_array” in different places of your controller, then using _.findWhere would be a bad idea. Why do you want to parse the same array by looping again and again?
Instead index the array and get the object immediately. You will get your required result in no time.
When we executed this change by replacing _.findWhere with indexed objects. Performance of our page was improved. The page was loading noticeably faster than before 🙂
So be sure when to use _.findWhere and when not to use.
I hope this post helps 🙂