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:
Andreas Kling
2026-03-23 20:30:19 +01:00
committed by Andreas Kling
parent e49ab8a1f2
commit b5babda288
Notes: github-actions[bot] 2026-03-24 07:29:35 +00:00
4 changed files with 14 additions and 3 deletions

View File

@@ -654,8 +654,7 @@ void EventLoop::perform_a_microtask_checkpoint()
// 4. For each environment settings object settingsObject whose responsible event loop is this event loop, notify about rejected promises given settingsObject's global object.
auto environments = GC::RootVector { heap(), m_related_environment_settings_objects };
for (auto& environment_settings_object : environments) {
auto& global = as<HTML::UniversalGlobalScopeMixin>(environment_settings_object->global_object());
global.notify_about_rejected_promises({});
environment_settings_object->universal_global_scope().notify_about_rejected_promises({});
}
// 5. Cleanup Indexed Database transactions.