mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-15 21:41:58 +00:00
LibJS+LibWeb: Replace StringOrSymbol usage with PropertyKey
Some checks are pending
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
- Avoids unnecessary conversions between StringOrSymbol and PropertyKey on the hot path of property access. - Simplifies the code by removing StringOrSymbol and using PropertyKey directly. There was no reason to have a separate StringOrSymbol type representing the same data as PropertyKey, just with the index key stored as a string. PropertyKey has been updated to use a tagged pointer instead of a Variant, so it still occupies 8 bytes, same as StringOrSymbol. 12% improvement on JetStream/gcc-loops.cpp.js 12% improvement on MicroBench/object-assign.js 7% improvement on MicroBench/object-keys.js
This commit is contained in:
parent
5495531118
commit
b559965448
Notes:
github-actions[bot]
2025-05-17 14:09:31 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: b559965448
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4761
12 changed files with 195 additions and 275 deletions
|
@ -1199,7 +1199,7 @@ Optional<ValueAndAttributes> Object::storage_get(PropertyKey const& property_key
|
|||
value = value_and_attributes->value;
|
||||
attributes = value_and_attributes->attributes;
|
||||
} else {
|
||||
auto metadata = shape().lookup(property_key.to_string_or_symbol());
|
||||
auto metadata = shape().lookup(property_key);
|
||||
if (!metadata.has_value())
|
||||
return {};
|
||||
|
||||
|
@ -1220,7 +1220,7 @@ bool Object::storage_has(PropertyKey const& property_key) const
|
|||
{
|
||||
if (property_key.is_number())
|
||||
return m_indexed_properties.has_index(property_key.as_number());
|
||||
return shape().lookup(property_key.to_string_or_symbol()).has_value();
|
||||
return shape().lookup(property_key).has_value();
|
||||
}
|
||||
|
||||
void Object::storage_set(PropertyKey const& property_key, ValueAndAttributes const& value_and_attributes)
|
||||
|
@ -1238,8 +1238,7 @@ void Object::storage_set(PropertyKey const& property_key, ValueAndAttributes con
|
|||
intrinsics->value.remove(property_key.as_string());
|
||||
}
|
||||
|
||||
auto property_key_string_or_symbol = property_key.to_string_or_symbol();
|
||||
auto metadata = shape().lookup(property_key_string_or_symbol);
|
||||
auto metadata = shape().lookup(property_key);
|
||||
|
||||
if (!metadata.has_value()) {
|
||||
static constexpr size_t max_transitions_before_converting_to_dictionary = 64;
|
||||
|
@ -1247,18 +1246,18 @@ void Object::storage_set(PropertyKey const& property_key, ValueAndAttributes con
|
|||
set_shape(m_shape->create_cacheable_dictionary_transition());
|
||||
|
||||
if (m_shape->is_dictionary())
|
||||
m_shape->add_property_without_transition(property_key_string_or_symbol, attributes);
|
||||
m_shape->add_property_without_transition(property_key, attributes);
|
||||
else
|
||||
set_shape(*m_shape->create_put_transition(property_key_string_or_symbol, attributes));
|
||||
set_shape(*m_shape->create_put_transition(property_key, attributes));
|
||||
m_storage.append(value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attributes != metadata->attributes) {
|
||||
if (m_shape->is_dictionary())
|
||||
m_shape->set_property_attributes_without_transition(property_key_string_or_symbol, attributes);
|
||||
m_shape->set_property_attributes_without_transition(property_key, attributes);
|
||||
else
|
||||
set_shape(*m_shape->create_configure_transition(property_key_string_or_symbol, attributes));
|
||||
set_shape(*m_shape->create_configure_transition(property_key, attributes));
|
||||
}
|
||||
|
||||
m_storage[metadata->offset] = value;
|
||||
|
@ -1276,18 +1275,18 @@ void Object::storage_delete(PropertyKey const& property_key)
|
|||
intrinsics->value.remove(property_key.as_string());
|
||||
}
|
||||
|
||||
auto metadata = shape().lookup(property_key.to_string_or_symbol());
|
||||
auto metadata = shape().lookup(property_key);
|
||||
VERIFY(metadata.has_value());
|
||||
|
||||
if (m_shape->is_cacheable_dictionary()) {
|
||||
m_shape = m_shape->create_uncacheable_dictionary_transition();
|
||||
}
|
||||
if (m_shape->is_uncacheable_dictionary()) {
|
||||
m_shape->remove_property_without_transition(property_key.to_string_or_symbol(), metadata->offset);
|
||||
m_shape->remove_property_without_transition(property_key, metadata->offset);
|
||||
m_storage.remove(metadata->offset);
|
||||
return;
|
||||
}
|
||||
m_shape = m_shape->create_delete_transition(property_key.to_string_or_symbol());
|
||||
m_shape = m_shape->create_delete_transition(property_key);
|
||||
m_storage.remove(metadata->offset);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue