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

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashSet;
use crossbeam_channel::{Receiver, select};
use devtools_traits::DevtoolScriptControlMsg;
@ -53,7 +55,7 @@ pub(crate) fn run_worker_event_loop<T, WorkerMsg, Event>(
let event = select! {
recv(worker_scope.control_receiver()) -> msg => T::from_control_msg(msg.unwrap()),
recv(task_queue.select()) -> msg => {
task_queue.take_tasks(msg.unwrap());
task_queue.take_tasks(msg.unwrap(), &HashSet::new());
T::from_worker_msg(task_queue.recv().unwrap())
},
recv(devtools_receiver) -> msg => T::from_devtools_msg(msg.unwrap()),
@ -72,7 +74,7 @@ pub(crate) fn run_worker_event_loop<T, WorkerMsg, Event>(
while !scope.is_closing() {
// Batch all events that are ready.
// The task queue will throttle non-priority tasks if necessary.
match task_queue.take_tasks_and_recv() {
match task_queue.take_tasks_and_recv(&HashSet::new()) {
Err(_) => match devtools_receiver.try_recv() {
Ok(message) => sequential.push(T::from_devtools_msg(message)),
Err(_) => break,