QuickBEAM.VM.Heap.Shapes (QuickBEAM v0.10.9)

Copy Markdown View Source

Hidden-class shape tracking for plain JS objects.

When objects are created with a consistent set of property names, they share a "shape" that maps each property name to a fixed tuple offset. Property access becomes O(1) tuple indexing instead of O(log n) map lookup.

Shape-backed objects are stored as

{:shape, shape_id, offsets_map, values_tuple, proto_ref}

in the process dictionary under the object's integer ID key.

Objects that gain accessors, internal keys, or otherwise become non-plain deopt back to regular maps.

Summary

Functions

Returns the canonical empty object shape id.

Convert a plain map (without __proto__) into a shape and values tuple. Returns {:ok, shape_id, values_tuple} or :ineligible.

Returns shape metadata for a shape id.

Return the ordered list of keys for shape_id.

Return the offset for key in shape_id, or :error.

Grow or update a values tuple at offset.

Check whether a stored heap value is shape-backed.

Reconstruct a plain map from a shape-backed representation.

Transition shape_id by adding key. Returns {new_shape_id, offset}.

Functions

empty_shape_id()

Returns the canonical empty object shape id.

from_map(map)

Convert a plain map (without __proto__) into a shape and values tuple. Returns {:ok, shape_id, values_tuple} or :ineligible.

get_shape(id)

Returns shape metadata for a shape id.

keys(shape_id)

Return the ordered list of keys for shape_id.

lookup(shape_id, key)

Return the offset for key in shape_id, or :error.

put_val(vals, offset, val)

Grow or update a values tuple at offset.

shape?(arg1)

Check whether a stored heap value is shape-backed.

to_map(shape_id, vals, proto)

Reconstruct a plain map from a shape-backed representation.

transition(shape_id, key)

Transition shape_id by adding key. Returns {new_shape_id, offset}.