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.