mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 02:29:21 +00:00
LibJS: Allow GetById to cache getters
1.25x speed-up on this microbenchmark: let o = { get x() { return 1; } }; for (let i = 0; i < 10_000_000; ++i) o.x; I looked into this because I noticed getter invocation when profiling long-running WPT tests. We already had the mechanism for non-getter properties, and the change to support getters turned out to be trivial.
This commit is contained in:
parent
e4245dc39e
commit
3c5819a6d2
Notes:
github-actions[bot]
2024-10-17 20:07:21 +00:00
Author: https://github.com/awesomekling
Commit: 3c5819a6d2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1843
2 changed files with 38 additions and 22 deletions
|
@ -911,26 +911,30 @@ ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_key, V
|
|||
return parent->internal_get(property_key, receiver, cacheable_metadata, PropertyLookupPhase::PrototypeChain);
|
||||
}
|
||||
|
||||
auto update_inline_cache = [&] {
|
||||
// Non-standard: If the caller has requested cacheable metadata and the property is an own property, fill it in.
|
||||
if (!cacheable_metadata || !descriptor->property_offset.has_value() || !shape().is_cacheable())
|
||||
return;
|
||||
if (phase == PropertyLookupPhase::OwnProperty) {
|
||||
*cacheable_metadata = CacheablePropertyMetadata {
|
||||
.type = CacheablePropertyMetadata::Type::OwnProperty,
|
||||
.property_offset = descriptor->property_offset.value(),
|
||||
.prototype = nullptr,
|
||||
};
|
||||
} else if (phase == PropertyLookupPhase::PrototypeChain) {
|
||||
VERIFY(shape().is_prototype_shape());
|
||||
VERIFY(shape().prototype_chain_validity()->is_valid());
|
||||
*cacheable_metadata = CacheablePropertyMetadata {
|
||||
.type = CacheablePropertyMetadata::Type::InPrototypeChain,
|
||||
.property_offset = descriptor->property_offset.value(),
|
||||
.prototype = this,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 3. If IsDataDescriptor(desc) is true, return desc.[[Value]].
|
||||
if (descriptor->is_data_descriptor()) {
|
||||
// Non-standard: If the caller has requested cacheable metadata and the property is an own property, fill it in.
|
||||
if (cacheable_metadata && descriptor->property_offset.has_value() && shape().is_cacheable()) {
|
||||
if (phase == PropertyLookupPhase::OwnProperty) {
|
||||
*cacheable_metadata = CacheablePropertyMetadata {
|
||||
.type = CacheablePropertyMetadata::Type::OwnProperty,
|
||||
.property_offset = descriptor->property_offset.value(),
|
||||
.prototype = nullptr,
|
||||
};
|
||||
} else if (phase == PropertyLookupPhase::PrototypeChain) {
|
||||
VERIFY(shape().is_prototype_shape());
|
||||
VERIFY(shape().prototype_chain_validity()->is_valid());
|
||||
*cacheable_metadata = CacheablePropertyMetadata {
|
||||
.type = CacheablePropertyMetadata::Type::InPrototypeChain,
|
||||
.property_offset = descriptor->property_offset.value(),
|
||||
.prototype = this,
|
||||
};
|
||||
}
|
||||
}
|
||||
update_inline_cache();
|
||||
return *descriptor->value;
|
||||
}
|
||||
|
||||
|
@ -944,6 +948,8 @@ ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_key, V
|
|||
if (!getter)
|
||||
return js_undefined();
|
||||
|
||||
update_inline_cache();
|
||||
|
||||
// 7. Return ? Call(getter, Receiver).
|
||||
return TRY(call(vm, *getter, receiver));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue