Skip to content

Array.observe() + sort() ==> event flooding #16

@about-code

Description

@about-code

Array.observe() should be specified in more detail with respect to sorting an array. In recent versions of Chrome the code snippnet below indicates that its current implementation of Array.observe doesn't scale well when it comes to sorting. There are a lot more change records generated than there are elements in the array. As it seems there's an update for each permutation. I think there should be just a single "update" change record after sorting, where "name" refers to a pseudo property 'order'.
Example:
{
type: 'update',
name: 'order',
object: [/sorted (orig. reference)/],
oldValue: [/* unsorted (reference to clone?)*/]
}

// i = 9 => changes.length = 54
// i = 9999 => changes.length = 143499
var x = [];
for (i = 9; i >= 0; i-=1) {
x.push(i);
}
Array.observe(x, function (changes) {
console.log(changes)
});
x.sort(function (e1, e2) {
if (e1 < e2) {
return - 1;
}else if(e1 > e2) {
return 1;
} else {
return 0;
}
});

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