rust-js / rjs

Rust JavaScript interpreter
98 stars 6 forks source link

Implement support for schema based object storage #17

Open pvginkel opened 9 years ago

pvginkel commented 9 years ago

Objects currently only support a hash based backing storage. Schema based storage should be implemented too.

The idea of schema based storage is that storage is separated into two parts. The backing storage for the object itself becomes a simple array. Indexes into this array are determined by a schema. This schema is a hash that maps names to indexes.

Every time a new key is added to the object, a new schema is created. This new schema is a copy of the previous schema that maps the new name to the end of the array. These two schemas are then connected to each other using a migration step, so:

When either a key is deleted, or the array becomes too large (must be determined based on performance tests), the backing storage for the object switches to a hash based store (current implementation). To make backing storage for instances even smaller, we could also state that we also automatically switch to classic storage when either an accessor is added or when either of the properties (writable, configurable, enumerable) is set to false.

This scheme has two primary advantages:

See e.g. http://jayconrod.com/posts/52/a-tour-of-v8-object-representation for more information on this.