mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-07 01:56:38 +00:00
LibJS: Skip PrivateEnvironment allocation if possible
If class doesn't have any private fields, we could avoid allocating PrivateEnvironment for it. This allows us to skip thousands of unnecessary PrivateEnvironment allocations on Discord.
This commit is contained in:
parent
d1fbb7b51e
commit
a3af7ca1a0
Notes:
github-actions[bot]
2025-07-30 11:03:14 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: a3af7ca1a0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5652
Reviewed-by: https://github.com/gmta ✅
1 changed files with 8 additions and 3 deletions
|
@ -2892,11 +2892,14 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ClassExpression::genera
|
|||
if (m_super_class)
|
||||
super_class = TRY(m_super_class->generate_bytecode(generator)).value();
|
||||
|
||||
generator.emit<Op::CreatePrivateEnvironment>();
|
||||
|
||||
bool did_emit_private_environment_allocation = false;
|
||||
for (auto const& element : m_elements) {
|
||||
auto opt_private_name = element->private_bound_identifier();
|
||||
if (opt_private_name.has_value()) {
|
||||
if (!did_emit_private_environment_allocation) {
|
||||
generator.emit<Op::CreatePrivateEnvironment>();
|
||||
did_emit_private_environment_allocation = true;
|
||||
}
|
||||
generator.emit<Op::AddPrivateName>(generator.intern_identifier(*opt_private_name));
|
||||
}
|
||||
}
|
||||
|
@ -2920,7 +2923,9 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ClassExpression::genera
|
|||
auto dst = choose_dst(generator, preferred_dst);
|
||||
generator.emit_with_extra_slots<Op::NewClass, Optional<Operand>>(elements.size(), dst, super_class.has_value() ? super_class->operand() : Optional<Operand> {}, *this, lhs_name, elements);
|
||||
|
||||
generator.emit<Op::LeavePrivateEnvironment>();
|
||||
if (did_emit_private_environment_allocation) {
|
||||
generator.emit<Op::LeavePrivateEnvironment>();
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue