mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
LibWeb: Cache UniversalGlobalScopeMixin pointer on ESO
Avoid expensive cross-hierarchy dynamic_cast from JS::Object to UniversalGlobalScopeMixin on every microtask checkpoint. Since UniversalGlobalScopeMixin is not in the JS::Object inheritance chain, as<UniversalGlobalScopeMixin>(JS::Object&) falls through to dynamic_cast, which is very costly. Profiling showed this taking ~14% of total CPU time. Add EnvironmentSettingsObject::universal_global_scope() backed by a pointer cached eagerly during initialization.
This commit is contained in:
committed by
Andreas Kling
parent
e49ab8a1f2
commit
b5babda288
Notes:
github-actions[bot]
2026-03-24 07:29:35 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/b5babda2881 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8598
@@ -19,6 +19,7 @@
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
||||
#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
|
||||
#include <LibWeb/HTML/UniversalGlobalScope.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/HTML/WorkerGlobalScope.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
@@ -56,6 +57,7 @@ void EnvironmentSettingsObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
m_module_map = realm.heap().allocate<ModuleMap>();
|
||||
m_universal_global_scope = &as<UniversalGlobalScopeMixin>(global_object());
|
||||
}
|
||||
|
||||
void EnvironmentSettingsObject::visit_edges(Cell::Visitor& visitor)
|
||||
@@ -109,6 +111,11 @@ JS::Object& EnvironmentSettingsObject::global_object()
|
||||
return realm().global_object();
|
||||
}
|
||||
|
||||
UniversalGlobalScopeMixin& EnvironmentSettingsObject::universal_global_scope()
|
||||
{
|
||||
return *m_universal_global_scope;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#responsible-event-loop
|
||||
EventLoop& EnvironmentSettingsObject::responsible_event_loop()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user