Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have millions of objects, all with the same set of known keys and you have so many of them that memory is an issue, then you probably don't want to store your data as javascript objects at all. </p> <p>You probably want to think about this like a database problem. You want:</p> <ol> <li>A semi-compact storage format</li> <li>A way to find the right record in the storage format (this depends upon what the data is and how you need to access it.</li> <li>A way to read the semi-compact storage format and turn it into a live javascript object only when you want to actually use that object in your code.</li> <li>A way to write changes back to the semi-compact storage format.</li> </ol> <p>For example, if you had seven keys (e.g. fields) and three were numbers and four were strings and one of the numbers was your lookup key, then you could do this:</p> <ul> <li>Create three typed arrays (one for each numeric value) </li> <li>Create one regular array. This will hold all the string values concatenated together with a unique separator character.</li> <li>Create a master key lookup object</li> </ul> <p>As you read your data in, presumably from multiple ajax calls, you do the following:</p> <ul> <li>Note the length of one of your arrays (they are all the same length) as this will be your new record number.</li> <li>Add the lookup key to the master key object and set the value of the key to be the record number.</li> <li>Add each numeric value to each typed array (each will be the record number index in the array)</li> <li>Concat all the string values together with a separator between them in order by key and then put the contactenated string value into the string array.</li> </ul> <p>Now you have a semi-compact storage format and a key lookup means. When you want to lookup a value, you use the master key lookup object. The value for the key will be the record number which is an index into the other arrays. You can create two functions that will find a record and return a javascript object form of the record (all data in key/value pairs on the object) and another function that will write an object (that might have changed = but the master key can't change) back to your storage format.</p> <p>This makes a few assumptions about your data that you have one master key that won't change that you use for lookup and that you can find a separator to bind all the string values together and then separate them apart later and that you can know when you go to store all this and that you know what the keys are and that the objects generally all have the same keys. </p> <p>If any of those assumptions are not true, then the design would have to be adapted to deal with that, but hopefully you get the idea of using something other than a giant array of objects to store your data and then constituting a given object only when you need to work with that record's data.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload