Skip to content

Projected arrays do not preserve sparse arrays #29

@ThomasMichon

Description

@ThomasMichon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions