Reputation: 2804
I have a very large lat/long dataset which I'd like to be able to filter and display client side. I've profiled and optimised the best I can, but is there is anything further than can be done to speed up performance?
Roughly
// Apparently I must post code... but out of context it would make no sense.
// Checkout jsfiddle.
Upvotes: 1
Views: 1016
Reputation: 8987
Your code creates a dependency between the criterias and each sample. I created a computed function in order to create a dependency between criterias and the samples array. This, in order to create only a few dependencies.
The modified code takes only 20ms against 2700ms for the original.
viewModel.computedLocations = ko.computed( function () {
var lat = viewModel.filters.lat();
var lng = viewModel.filters.lng();
var locs = viewModel.locations();
ko.utils.arrayForEach(locs, function (item) {
item.roughDistance = equirectangularApproximation(item.lat, item.lng, lat, lng);
item.closeDistance = sphericalLawOfCosines(item.lat, item.lng, lat, lng);
item.closeDistanceStatic = item.closeDistance;
item.exactDistance = haversine(item.lat, item.lng, lat, lng);
});
return locs;
});
I hope it helps.
Upvotes: 4