perf(web-surface): throttle idle Servo polling

This commit is contained in:
2026-05-15 23:25:09 -04:00
parent 736ff08e90
commit ca8f118785
13 changed files with 500 additions and 242 deletions
+14 -1
View File
@@ -1,4 +1,4 @@
use std::time::Instant;
use std::time::{Duration, Instant};
use ely_domain::TabId;
use gpui::{Bounds, Pixels};
@@ -116,6 +116,7 @@ pub(super) struct PerTabSurface {
pub(super) viewport_size: Option<WebSurfaceSize>,
pub(super) last_ensure_key: Option<WebSurfaceEnsureKey>,
pub(super) hover_point: Option<WebSurfaceClickPoint>,
last_hover_enqueued_at: Option<Instant>,
pub(super) click_point: Option<WebSurfaceClickState>,
pub(super) pending_scroll_delta: Option<WebSurfaceScrollDelta>,
pub(super) pending_scroll_point: Option<WebSurfaceClickPoint>,
@@ -132,6 +133,7 @@ impl PerTabSurface {
viewport_size: None,
last_ensure_key: None,
hover_point: None,
last_hover_enqueued_at: None,
click_point: None,
pending_scroll_delta: None,
pending_scroll_point: None,
@@ -146,6 +148,15 @@ impl PerTabSurface {
self.pending_input_started_at.get_or_insert_with(Instant::now);
}
pub(super) fn hover_is_throttled(&self, now: Instant) -> bool {
self.last_hover_enqueued_at
.is_some_and(|last| now.duration_since(last) < HOVER_INPUT_MIN_INTERVAL)
}
pub(super) fn mark_hover_enqueued(&mut self, now: Instant) {
self.last_hover_enqueued_at = Some(now);
}
pub(super) fn should_ensure(&self, key: &WebSurfaceEnsureKey) -> bool {
self.last_ensure_key.as_ref() != Some(key) || self.has_pending_input()
}
@@ -171,6 +182,8 @@ impl PerTabSurface {
}
}
const HOVER_INPUT_MIN_INTERVAL: Duration = Duration::from_millis(32);
#[derive(Clone, Debug, Eq, PartialEq)]
pub(super) struct WebSurfaceEnsureKey {
requested_url: String,