knockout-projections
knockout-projections copied to clipboard
Projected arrays do not preserve sparse arrays
Observable arrays assume that their wrapped arrays can be sparse, and array change tracking appears to work on sparse arrays (even if it iterates numerically instead of by key). However, invoking map() on a sparse array produces an array which is no longer sparse, which significantly drops performance.
var source = ko.observableArray(new Array(100000));
// Object.keys(source()).length is 0
var projection = source.map(function (x) { return x * 2; });
// Object.keys(projection()).length is 100000
I get the impression that if the initial mapping process and the index update process iterated over the keys of the underlying arrays, then the projected array could remain sparse.