I would like a good answer here, not looking for any answers that are 'Have you tried X?', would rather have a knowledgeable source with a firm answer.
I have an observable array that I am using to fill in a chart. The observable array could contain up to 10k POJO's that are retrieved from Breeze.js in the local cache. When I first go out and get the data from the server, and then make a call against the local cache it is returned almost instantaneously.
On the next call, it gets exponentially slower. The objects being returned are not each observables nor do they contain observables, since I am performing a Breeze query with select they are POJO's. The problem is they continue to get slower and slower as I go back and continue to get the same data set. It is almost leading me to think somehow I am creating a memory leak in the observable array somehow.
In my view -
<h1>There are <span data-bind="text: chartData().length"></span> chart items</h1>
In my view model -
var chartData = ko.computed(function () {
var myArray = ko.observableArray();
var params = { xmin: xMin(), xmax: xMax() };
if (!initialized) { return myArray(); }
datacontext.getData(myArray, params.xmin, params.xmax false);
return myArray();
}).extend({ throttle: 2000 });
In a datacontext.js file where the query is executing -
if (!forceRemote) {
var thisData = manager.executeQueryLocally(query);
myObservable([]);
var myArray = myObservable();
ko.utils.arrayPushAll(myArray, thisData);
return myObservable.valueHasMutated();
}
I tried the arrayPushAll and value mutation based on a recommendation from another SO.com question but it doesn't appear to be any faster than setting myObservable([]) and then setting it equal to thisData.
Because of the large data set I would like to reduce this to as short of a recalculation as possible.
The reason I am setting the xmin and xmax as params is to make the computed dependent on the two observables...