script: Skip RAII guard and early return when input event queue is empty (#43301)

This is a hot path:
- there is a lot of processing in `handle_pending_input_events`: JS
realm entry, temporary variable creation, value assignment etc.
- we acquire a RAII guard before calling the function.

If the event queue is empty, this would result in unnecessary overhead
on the hot path.
We skip all above work in this case.

Testing: This is an optimization that should not change visible
behaviour,
thus covered by all the testdriver tests.

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye
2026-03-16 15:15:20 +08:00
committed by GitHub
parent fc76797034
commit 709e8d5548
2 changed files with 8 additions and 3 deletions

View File

@@ -1092,6 +1092,9 @@ impl ScriptThread {
warn!("Input event sent to a pipeline with a closed window {pipeline_id}.");
return;
}
if !document.event_handler().has_pending_input_events() {
return;
}
let _guard = ScriptUserInteractingGuard::new(self.is_user_interacting.clone());
document.event_handler().handle_pending_input_events(can_gc);