Skip to content

Array methods (sort, forEach, map...) are slow on big Reactor arrays #42

@Sliverside

Description

@Sliverside

Hi,

First thank you for this library !

I was doing some test and i find-out that Reactor arrays new Reactor([]) are really slow when using the sort method myReactor.sort on big Reactor arrays. For an array of 1000 items it take me ~ 30ms and for 5000 items it take me ~6800ms and this his exponential.

The same problem happened with Array.forEach and Array.map but duration is linear.

A workaround is to use shuck, Array.splice and Array.length like that :

const reactorArray = new Reactor([])
const newArray = shuck(reactorArray).sort();
reactorArray.length = 0; // without this line, the problem stay the same
reactorArray.splice(0, 0, ...newArray);

i have done a CodePen (https://codepen.io/sliverside/pen/yLZoJWJ) where you can see/modify/adapt my tests.

Thanks for your time !

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