Question

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?

  • Accuracy needs to be at the mile/kilometre level.
  • I'd need IE 7/8/9/10 support although I'm accepting the further down we go the performance will likely get worse.
  • I have not absolute dependency on any library, whatever is best for the job.

Roughly

  • Chrome: 1.1s
  • Firefox: 0.9s
  • IE10: 5.1s
  • IE9: 3s

http://jsfiddle.net/hRvKz/

// Apparently I must post code... but out of context it would make no sense.
// Checkout jsfiddle.
Was it helpful?

Solution

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;
});

See fiddle

I hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top