Suppose I have an array of some basic objects in JavaScript:
[
{a: 'something', b: 'something else', c: 'other' },
{a: 'something 2', b: 'something else 2', c: 'other 2' },
// etc.
]
When I reach several hundred thousand of these objects, memory usage is already in the gigabytes under Node.js. How can I make this more efficient?
- All of the keys are going to be the same for each object, but not necessarily populated in the same order. I suppose I could translate to an array of arrays, but there is overhead in all the conversion back and forth.
- I know the types of each value in the object ahead of time.
Is there some sort of off-the-shelf in-memory table structure I can use?
I had considered using SQLite3 in-memory but its non-atomic nature prevented me from using it will in my application. Perhaps there is some native JS alternative so that I could re-use it in browsers as well?
{a: ['something', 'something 2'], b: ['something else', 'something else 2'], c: [...]}? That's quite minimal... 1 object, 3 properties, 3 arrays, all the values (can't use "less" than the values take to store)