Efficient in-memory arrays of hashes with JavaScript -


suppose have array of basic objects in javascript:

[   {a: 'something', b: 'something else', c: 'other' },   {a: 'something 2', b: 'something else 2', c: 'other 2' },   // etc. ] 

when reach several hundred thousand of these objects, memory usage in gigabytes under node.js. how can make more efficient?

  • all of keys going same each object, not populated in same order. suppose translate array of arrays, there overhead in conversion , forth.
  • i know types of each value in object ahead of time.

is there sort of off-the-shelf in-memory table structure can use?

i had considered using sqlite3 in-memory non-atomic nature prevented me using in application. perhaps there native js alternative re-use in browsers well?

use array index using object boundary of 3 items per object

data = ['something', 'something else', 'other', 'something 2', 'something else 2', 'other 2'];  function getobjectat(index){  var offset = index * 3;  return { : data[offset], b : data[offset + 1],  c : data[offset + 2]}; } 

the memory footprint should smaller, of course there many ots solutions out there redis or hbase.


Comments