script: Reduce ScriptThread TLS usage (#38875)

We store a pointer to the ScriptThread singleton for a thread in
thread-local storage. While we don't have yet have profiles pointing to
this TLS access as a hot spot, we can remove a potential performance
footgun without a lot of effort by passing around small pieces of data
that we otherwise need to fetch from the ScriptThread.

Testing: Existing WPT is sufficient
Fixes: part of #37969

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-08-30 12:51:40 -04:00 committed by GitHub
parent d1da1a995c
commit c97ec1b2fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 129 additions and 68 deletions

View file

@ -52,7 +52,6 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::window::Window;
use crate::script_runtime::{CanGc, JSContext, JSContext as SafeJSContext};
use crate::script_thread::ScriptThread;
/// <https://html.spec.whatwg.org/multipage/#htmlconstructor>
fn html_constructor(
@ -391,14 +390,6 @@ fn get_constructor_object_from_local_name(
true
}
pub(crate) fn pop_current_element_queue(can_gc: CanGc) {
ScriptThread::pop_current_element_queue(can_gc);
}
pub(crate) fn push_new_element_queue() {
ScriptThread::push_new_element_queue();
}
pub(crate) fn call_html_constructor<T: DerivedFrom<Element> + DomObject>(
cx: JSContext,
args: &CallArgs,

View file

@ -19,9 +19,7 @@ use script_bindings::settings_stack::StackEntry;
use crate::DomTypes;
use crate::dom::bindings::codegen::{InterfaceObjectMap, PrototypeList};
use crate::dom::bindings::constructor::{
call_html_constructor, pop_current_element_queue, push_new_element_queue,
};
use crate::dom::bindings::constructor::call_html_constructor;
use crate::dom::bindings::conversions::DerivedFrom;
use crate::dom::bindings::error::{Error, report_pending_exception, throw_dom_exception};
use crate::dom::bindings::principals::PRINCIPALS_CALLBACKS;
@ -33,6 +31,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::windowproxy::WindowProxyHandler;
use crate::realms::InRealm;
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
use crate::script_thread::ScriptThread;
#[derive(JSTraceable, MallocSizeOf)]
/// Static data associated with a global object.
@ -185,10 +184,10 @@ impl DomHelpers<crate::DomTypeHolder> for crate::DomTypeHolder {
}
fn push_new_element_queue() {
push_new_element_queue()
ScriptThread::custom_element_reaction_stack().push_new_element_queue()
}
fn pop_current_element_queue(can_gc: CanGc) {
pop_current_element_queue(can_gc)
ScriptThread::custom_element_reaction_stack().pop_current_element_queue(can_gc)
}
fn reflect_dom_object<T, U>(obj: Box<T>, global: &U, can_gc: CanGc) -> DomRoot<T>