From 20655b8ebf3efcb2fc7b285735caa329ab9caa58 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 4 Jun 2025 16:54:09 +0200 Subject: [PATCH] LibJS: Add simple storage fast path in internal_get_own_property() ...of Array. This allows us to avoid lots of unnecessary for simple arrays checks that happen in `Object::internal_get_own_property()`. --- Libraries/LibJS/Runtime/Array.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Libraries/LibJS/Runtime/Array.cpp b/Libraries/LibJS/Runtime/Array.cpp index f5ead14928f..131d75894cd 100644 --- a/Libraries/LibJS/Runtime/Array.cpp +++ b/Libraries/LibJS/Runtime/Array.cpp @@ -276,6 +276,22 @@ ThrowCompletionOr compare_array_elements(VM& vm, Value x, Value y, Funct // NON-STANDARD: Used to return the value of the ephemeral length property ThrowCompletionOr> Array::internal_get_own_property(PropertyKey const& property_key) const { + // OPTIMIZATION: Fast path for arrays with simple indexed properties storage. + auto const* storage = indexed_properties().storage(); + if (property_key.is_number() && storage && storage->is_simple_storage()) { + auto const& simple_storage = static_cast(*storage); + auto value_and_attributes = simple_storage.get(property_key.as_number()); + if (value_and_attributes.has_value()) { + PropertyDescriptor descriptor; + descriptor.value = value_and_attributes->value; + descriptor.writable = true; + descriptor.enumerable = true; + descriptor.configurable = true; + return descriptor; + } + return Optional {}; + } + auto& vm = this->vm(); if (property_key.is_string() && property_key.as_string() == vm.names.length.as_string()) return PropertyDescriptor { .value = Value(indexed_properties().array_like_size()), .writable = m_length_writable, .enumerable = false, .configurable = false };