seald / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
351 stars 32 forks source link

Fix stack overflow #53

Open chrismwendt opened 9 months ago

chrismwendt commented 9 months ago

This replaces a spread call validDocs.push(...docs) where validDocs was empty with simple assignment validDocs = docs to avoid a stack overflow with a big docs array.

RangeError: Maximum call stack size exceeded

Spread calls use stack space, so foo.push(...REALLY_BIG_ARRAY) uses LOTS of stack space and it can easily cause a stack overflow.

Llorx commented 2 months ago

This fix makes a lot of sense as there's no need to push to an empty array when you can just reassign it. Just thinking on optimizations it makes a lot of sense. How is it going @tex0l @arantes555