Ant's dynamic property performance is driven by two primary architectural tracks:
- computed-property inline caches for
obj[key] access. - numeric-index storage for plain objects used as sparse arrays or heaps.
Beyond these core tracks, Ant implements several supporting optimization buckets to improve performance for specific workloads:
Key Conversion Fast Paths
Reduces overhead when converting property keys. This includes specializing small non-negative integer keys, caching canonical string forms for hot numeric keys, and avoiding duplicate key string creation between GET_ELEM / PUT_ELEM and proxy dispatch.
Proxy Dispatch Fast Paths
Reduces the setup cost around Proxy trap calls. Improvements include caching handler get / set trap lookups when the handler shape is stable, reusing normalized property keys, and skipping expensive invariant checks when the target shape proves no relevant non-configurable property can exist.
Megamorphic or Dictionary Mode
For objects with high-cardinality add/delete patterns where shape-based slot layouts become inefficient, Ant can switch plain objects to a 'dictionary-mode' property storage. This helps workloads using many different string keys, not just integer-like keys.
Trap-Aware Benchmarking
To measure these optimizations, benchmarks should separate the following costs:
- Plain numeric computed property access
- Plain string computed property access
- Pass-through proxy access
- Demo-shaped proxy access (using
Number(prop), isNaN, and Set.has) - High-cardinality add/delete workloads (for dictionary-mode)