Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
bench(desktop-gpui): editor bench scenarios for the caption download tick and seeded caption fields
Richie McIlroy379cd6bb8cb3
diff --git a/apps/desktop-gpui/src/editor_bench.rs b/apps/desktop-gpui/src/editor_bench.rsindex c1c9c5f31..824d5cd19 100644--- a/apps/desktop-gpui/src/editor_bench.rs+++ b/apps/desktop-gpui/src/editor_bench.rs@@ -8,7 +8,10 @@ use std::time::{Duration, Instant};use gpui::{AsyncApp, Context, Window, WindowHandle};-use crate::{draw_bench, editor_timeline, editor_window::EditorWindow};+use crate::{+ draw_bench, editor_panels::FieldKey, editor_sidebar::SidebarTab, editor_timeline,+ editor_window::EditorWindow,+};const WARMUP_FRAMES: usize = 60;const MEASURED_FRAMES: usize = 300;@@ -17,6 +20,9 @@ const READY_POLL: Duration = Duration::from_millis(50);const READY_TIMEOUT: Duration = Duration::from_secs(30);const FOLLOW_ZOOM_SECS: f64 = 20.0;const FOLLOW_START_FRACTION: f64 = 0.82;+/// A generated transcript for a few minutes of speech, every segment of which+/// has been selected once, so each has its three sidebar fields.+const SEEDED_CAPTION_SEGMENTS: usize = 300;#[derive(Clone, Copy)]enum Scenario {@@ -25,6 +31,8 @@ enum Scenario {Hover,Follow,Clean,+ CaptionDownload,+ TickFields,}impl Scenario {@@ -35,6 +43,8 @@ impl Scenario {Self::Hover => "hover",Self::Follow => "follow",Self::Clean => "clean",+ Self::CaptionDownload => "caption-download",+ Self::TickFields => "tick-fields",}}@@ -72,6 +82,22 @@ impl Scenario {}view.bench_zoom_to(view.total_duration(), cx);}+ Self::CaptionDownload => {+ if view.playing {+ view.stop_for_measurement(cx);+ }+ view.sidebar.tab = SidebarTab::Captions;+ cx.notify();+ }+ Self::TickFields => {+ if view.playing {+ view.stop_for_measurement(cx);+ }+ view.sidebar.tab = SidebarTab::Background;+ seed_caption_fields(view, window, cx);+ cx.notify();+ view.toggle_play(window, cx);+ }}}@@ -83,7 +109,7 @@ impl Scenario {cx: &mut Context<EditorWindow>,) {match self {- Self::Tick | Self::TickZoomedOut | Self::Follow => {+ Self::Tick | Self::TickZoomedOut | Self::Follow | Self::TickFields => {view.invalidate_playback_chrome(window, cx)}Self::Hover => {@@ -94,6 +120,51 @@ impl Scenario {view.timeline_hover(x, window, cx);}Self::Clean => {}+ Self::CaptionDownload if self.control(iteration) => cx.notify(),+ Self::CaptionDownload => view.repaint_caption_download(cx),+ }+ }++ /// Frames interleaved with the measured ones as an in-process reference:+ /// a whole-editor notify, which is what a download tick used to cost.+ fn control(self, iteration: usize) -> bool {+ matches!(self, Self::CaptionDownload) && iteration % 2 == 1+ }+}++/// In memory only: the segments are never saved, and the fields are created+/// the way selecting each segment in turn would create them.+fn seed_caption_fields(+ view: &mut EditorWindow,+ window: &mut Window,+ cx: &mut Context<EditorWindow>,+) {+ let step = view.total_duration() / SEEDED_CAPTION_SEGMENTS as f64;+ let Some(timeline) = view.project.timeline.as_mut() else {+ return;+ };+ timeline.caption_segments = (0..SEEDED_CAPTION_SEGMENTS)+ .map(|index| cap_project::CaptionTrackSegment {+ id: format!("bench-{index}"),+ start: index as f64 * step,+ end: (index as f64 + 0.8) * step,+ text: format!("Caption line {index} with a handful of words"),+ words: Vec::new(),+ fade_duration_override: None,+ linger_duration_override: None,+ position_override: None,+ color_override: None,+ background_color_override: None,+ font_size_override: None,+ })+ .collect();+ for index in 0..SEEDED_CAPTION_SEGMENTS {+ for key in [+ FieldKey::CaptionText(index),+ FieldKey::CaptionStart(index),+ FieldKey::CaptionEnd(index),+ ] {+ view.ensure_field(key, window, cx);}}}@@ -146,6 +217,8 @@ pub(crate) async fn run(handle: WindowHandle<EditorWindow>, cx: &mut AsyncApp) {Scenario::Hover,Scenario::Follow,Scenario::Clean,+ Scenario::CaptionDownload,+ Scenario::TickFields,] {if handle.update(cx, |view, window, cx| scenario.prepare(view, window, cx))@@ -156,17 +229,22 @@ pub(crate) async fn run(handle: WindowHandle<EditorWindow>, cx: &mut AsyncApp) {}let mut draw_us = Vec::with_capacity(MEASURED_FRAMES);+ let mut control_us = Vec::new();let mut built = 0;let mut reused = 0;for iteration in 0..WARMUP_FRAMES + MEASURED_FRAMES {cx.background_executor().timer(FRAME_INTERVAL).await;+ // The step gets its own update so the notifies it queues for+ // observers (each editor section observes the editor) are flushed+ // into the timed draw instead of the next, untimed, frame.+ let before = handle+ .update(cx, |view, window, cx| {+ scenario.step(iteration, view, window, cx);+ view.waveform_cache_stats()+ })+ .ok();let elapsed = cx.update(|cx| {- let before = handle- .update(cx, |view, window, cx| {- scenario.step(iteration, view, window, cx);- view.waveform_cache_stats()- })- .ok()?;+ let before = before?;let elapsed = draw_bench::timed_draw(handle.into(), cx)?;let after = handle.update(cx, |view, _, _| view.waveform_cache_stats())@@ -180,21 +258,29 @@ pub(crate) async fn run(handle: WindowHandle<EditorWindow>, cx: &mut AsyncApp) {if iteration >= WARMUP_FRAMES&& let Some((elapsed, draw_built, draw_reused)) = elapsed{+ if scenario.control(iteration) {+ control_us.push(elapsed.as_secs_f64() * 1e6);+ continue;+ }draw_us.push(elapsed.as_secs_f64() * 1e6);built += draw_built;reused += draw_reused;}}- if draw_us.len() < MEASURED_FRAMES {+ if draw_us.len() + control_us.len() < MEASURED_FRAMES {eprintln!("timeline-bench: only {} of {MEASURED_FRAMES} {} draws completed",- draw_us.len(),+ draw_us.len() + control_us.len(),scenario.label());std::process::exit(1);}draw_bench::report("timeline-bench", scenario.label(), &mut draw_us);+ if !control_us.is_empty() {+ let label = format!("{}-full-notify", scenario.label());+ draw_bench::report("timeline-bench", &label, &mut control_us);+ }println!("timeline-bench: {} waveform paths built {built} / reused {reused} in {} timed draws",scenario.label(),@@ -202,5 +288,28 @@ pub(crate) async fn run(handle: WindowHandle<EditorWindow>, cx: &mut AsyncApp) {);}+ // The per-render field sync on its own, with the seeded fields in place.+ let mut sync_us = Vec::with_capacity(MEASURED_FRAMES);+ for iteration in 0..WARMUP_FRAMES + MEASURED_FRAMES {+ let Ok((elapsed, fields)) = handle.update(cx, |view, window, cx| {+ if view.playing {+ view.stop_for_measurement(cx);+ }+ let started = Instant::now();+ view.sync_fields(window, cx);+ (started.elapsed(), view.fields.len())+ }) else {+ eprintln!("timeline-bench: the editor window closed");+ std::process::exit(1);+ };+ if iteration == 0 {+ println!("timeline-bench: sync-fields over {fields} fields");+ }+ if iteration >= WARMUP_FRAMES {+ sync_us.push(elapsed.as_secs_f64() * 1e6);+ }+ }+ draw_bench::report("timeline-bench", "sync-fields", &mut sync_us);+std::process::exit(0);}diff --git a/apps/desktop-gpui/src/editor_tabs.rs b/apps/desktop-gpui/src/editor_tabs.rsindex d59830d16..5dec243e4 100644--- a/apps/desktop-gpui/src/editor_tabs.rs+++ b/apps/desktop-gpui/src/editor_tabs.rs@@ -3126,7 +3126,10 @@ impl EditorWindow {.timer(Duration::from_millis(150)).await;let active = transcription::download_active();- if this.update(cx, |_, cx| cx.notify()).is_err() {+ if this+ .update(cx, |this, cx| this.repaint_caption_download(cx))+ .is_err()+ {break;}if !active {@@ -3137,6 +3140,11 @@ impl EditorWindow {.detach();}+ /// One tick of [`Self::spawn_caption_download_poll`].+ pub(crate) fn repaint_caption_download(&mut self, cx: &mut Context<Self>) {+ cx.notify();+ }+/// `downloadModel` (`CaptionsTab.tsx:643-690`). The download runs on the/// tokio runtime and survives this window; the poll task repaints.fn start_caption_model_download(&mut self, cx: &mut Context<Self>) {