1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00

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
This commit is contained in:
Andreas Kling 2025-05-02 11:27:06 +02:00 committed by Andreas Kling
parent ea77092100
commit 2ef2e75cdc
Notes: github-actions[bot] 2025-05-03 06:09:05 +00:00

View file

@ -1739,7 +1739,9 @@ inline ThrowCompletionOr<Value> 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;