From 76a56decff31c108daecc27378abe487bca1d3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Sat, 16 May 2026 04:55:47 -0400 Subject: [PATCH] perf(sidecar): avoid second hardware warmup readback --- .../src/bin/ely_servo_sidecar/live.rs | 25 +++++-------------- .../tests/hardware_rendering_context.rs | 3 +++ .../ely_servo_host/tests/live_perf_bench.rs | 4 +++ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/crates/ely_servo_host/src/bin/ely_servo_sidecar/live.rs b/crates/ely_servo_host/src/bin/ely_servo_sidecar/live.rs index 6dd07a0..e5b692a 100644 --- a/crates/ely_servo_host/src/bin/ely_servo_sidecar/live.rs +++ b/crates/ely_servo_host/src/bin/ely_servo_sidecar/live.rs @@ -307,10 +307,7 @@ fn paint_hardware_surface_frame( if !payloadless_surface_pool_ready(readiness, session.width, session.height) { return paint_readback_frame(host, session, !has_pending_frame); } - let (outcome, identity) = paint_hardware_surface_report(host, session, !has_pending_frame)?; - if !surface_has_been_published(readiness.published_surface_ids, readiness.tab_id, identity) { - return paint_readback_frame(host, session, true); - } + let (outcome, _) = paint_hardware_surface_report(host, session, !has_pending_frame)?; Ok((outcome, true)) } @@ -370,16 +367,15 @@ fn payloadless_surface_pool_ready( let matching = published .iter() .filter(|identity| identity.width == width && identity.height == height) - .take(2) .copied() .collect::>(); - if matching.len() < 2 { + if matching.is_empty() { return false; } !readiness.require_client_ready_surfaces || matching .iter() - .all(|identity| readiness.ready_surface_ids.contains(&identity.surface_id)) + .any(|identity| readiness.ready_surface_ids.contains(&identity.surface_id)) } #[derive(Clone, Copy)] @@ -418,15 +414,6 @@ fn payloadless_readiness<'a>( } } -#[cfg(all(feature = "hardware-render", target_os = "macos"))] -fn surface_has_been_published( - published_surface_ids: &HashMap>, - tab_id: &str, - identity: IOSurfaceIdentity, -) -> bool { - published_surface_ids.get(tab_id).is_some_and(|published| published.contains(&identity)) -} - #[cfg(test)] mod tests { use super::*; @@ -444,11 +431,11 @@ mod tests { #[cfg(all(feature = "hardware-render", target_os = "macos"))] #[test] - fn payloadless_pool_waits_for_client_ready_surfaces_when_required() { + fn payloadless_pool_accepts_one_client_ready_surface() { let published = published_identities([identity(7, 800, 600), identity(8, 800, 600)]); - assert!(!payloadless_surface_pool_ready(readiness(&published, &[7], true), 800, 600)); - assert!(payloadless_surface_pool_ready(readiness(&published, &[7, 8], true), 800, 600)); + assert!(!payloadless_surface_pool_ready(readiness(&published, &[], true), 800, 600)); + assert!(payloadless_surface_pool_ready(readiness(&published, &[7], true), 800, 600)); } #[cfg(all(feature = "hardware-render", target_os = "macos"))] diff --git a/crates/ely_servo_host/tests/hardware_rendering_context.rs b/crates/ely_servo_host/tests/hardware_rendering_context.rs index dc95b75..9a6e164 100644 --- a/crates/ely_servo_host/tests/hardware_rendering_context.rs +++ b/crates/ely_servo_host/tests/hardware_rendering_context.rs @@ -14,6 +14,7 @@ use dpi::PhysicalSize; use ely_servo_host::HardwareOffscreenContext; +use servo::RenderingContext; #[test] fn constructs_or_explains_why_not() { @@ -52,6 +53,8 @@ fn extracts_iosurface_mach_port_from_current_surface() -> Result<(), String> { } }; + context.prepare_for_rendering(); + context.present(); let first = context .current_iosurface_mach_port() .map_err(|error| format!("first IOSurface mach port extraction failed: {error:?}"))?; diff --git a/crates/ely_servo_host/tests/live_perf_bench.rs b/crates/ely_servo_host/tests/live_perf_bench.rs index 7386986..457e41c 100644 --- a/crates/ely_servo_host/tests/live_perf_bench.rs +++ b/crates/ely_servo_host/tests/live_perf_bench.rs @@ -163,6 +163,10 @@ fn run_live_bench() -> Result<(), Box> { ); if kind == "hardware" { let full_readback_budget = viewport_bytes * u64::from(frames); + assert_eq!( + outcome.readback_rgba_bytes, viewport_bytes, + "hardware path should read back only the initial visible frame" + ); assert!( total_rgba_bytes < full_readback_budget, "hardware path stayed on full readback: {total_rgba_bytes} >= {full_readback_budget}"