From 2ef2e75cdcb6edbbaf34f55b8596167cd3ee9b39 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 2 May 2025 11:27:06 +0200 Subject: [PATCH] LibJS: Reduce HashTable rehashing in get_object_property_iterator() Apply a little ensure_capacity() to avoid excessive rehashing of the property key table when enumerating a large number of properties. 1.23x speedup on MicroBench/for-in-indexed-properties.js --- Libraries/LibJS/Bytecode/Interpreter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Bytecode/Interpreter.cpp b/Libraries/LibJS/Bytecode/Interpreter.cpp index 47dca23d03f..2b93b233068 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1739,7 +1739,9 @@ inline ThrowCompletionOr get_object_property_iterator(VM& vm, Value value // Collect all keys immediately (invariant no. 5) for (auto object_to_check = GC::Ptr { object.ptr() }; object_to_check && !seen_objects.contains(*object_to_check); object_to_check = TRY(object_to_check->internal_get_prototype_of())) { seen_objects.set(*object_to_check); - for (auto& key : TRY(object_to_check->internal_own_property_keys())) { + auto keys = TRY(object_to_check->internal_own_property_keys()); + properties.ensure_capacity(properties.size() + keys.size()); + for (auto& key : keys) { if (key.is_symbol()) continue;