4 ms·
If you are using the spread operator to copy data to create a new JS object in a performance sensitive loop, it will actually have a big enough overhead that yo
by Tehnix 4y ago
If you are using the spread operator to copy data to create a new JS object in a performance sensitive loop, it will actually have a big enough overhead that you’ll have performance gains by listing the fields explicitly.
Spreading introduces an overhead at runtime since the object has to be traversed to figure out what it contains before JS will know what to copy over.
Edit: just to be clear, unless you’re looping over a million items or something up there, you should not care :)
- mst 4y agoI wonder if v8 can optimise that if the object is constructed such that it can infer a 'type' for it (IIRC if v8 can see the list of keys at object construction time it remembers what they are for a bunch of things, no idea if this is one of them.)