Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
perf(editor): skip timeline rebuild for model-irrelevant slider edits
Pravina3817dd4d71a
diff --git a/apps/desktop-gpui/src/editor_color.rs b/apps/desktop-gpui/src/editor_color.rsindex 414d9d746..03311d6cd 100644--- a/apps/desktop-gpui/src/editor_color.rs+++ b/apps/desktop-gpui/src/editor_color.rs@@ -326,6 +326,25 @@ pub enum GradeSlider {}impl GradeSlider {+ /// Whether this slider writes a field+ /// [`crate::editor_timeline::TimelineModel::build`] or+ /// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match+ /// is exhaustive so a new slider has to make the choice explicitly.+ pub(crate) fn changes_timeline_model(self) -> bool {+ match self {+ Self::Grain+ | Self::Intensity+ | Self::Exposure+ | Self::Contrast+ | Self::Saturation+ | Self::Temperature+ | Self::Tint+ | Self::Fade+ | Self::SplitTone+ | Self::Vignette => false,+ }+ }+/// The nine rows inside "Fine-tune colors", in order.pub const ADJUST: [GradeSlider; 9] = [Self::Intensity,@@ -492,17 +511,23 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- self.edit_project("grade", window, cx, move |project| {- let grade = Self::grade_mut(project, target);- if (slider.read(grade) - value).abs() < f32::EPSILON {- return false;- }- slider.write(grade, value);- if !slider.keeps_preset() {- grade.preset = PRESET_CUSTOM.to_string();- }- true- });+ self.edit_project_with_rebuild(+ slider.changes_timeline_model(),+ "grade",+ window,+ cx,+ move |project| {+ let grade = Self::grade_mut(project, target);+ if (slider.read(grade) - value).abs() < f32::EPSILON {+ return false;+ }+ slider.write(grade, value);+ if !slider.keeps_preset() {+ grade.preset = PRESET_CUSTOM.to_string();+ }+ true+ },+ );}fn preset_image(index: usize) -> Option<Arc<RenderImage>> {diff --git a/apps/desktop-gpui/src/editor_sidebar.rs b/apps/desktop-gpui/src/editor_sidebar.rsindex aa0b851af..0d06270f8 100644--- a/apps/desktop-gpui/src/editor_sidebar.rs+++ b/apps/desktop-gpui/src/editor_sidebar.rs@@ -653,6 +653,31 @@ pub enum BgSlider {}impl BgSlider {+ /// Whether this slider writes a field+ /// [`crate::editor_timeline::TimelineModel::build`] or+ /// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match+ /// is exhaustive so a new slider has to make the choice explicitly.+ pub(crate) fn changes_timeline_model(self) -> bool {+ match self {+ Self::Blur+ | Self::Padding+ | Self::Rounding+ | Self::MotionBlur+ | Self::BorderWidth+ | Self::BorderOpacity+ | Self::NotchWidth+ | Self::NotchHeight+ | Self::NotchX+ | Self::Shadow+ | Self::ShadowSize+ | Self::ShadowOpacity+ | Self::ShadowBlur+ | Self::GradientAngle+ | Self::GradientNoise+ | Self::GradientGrain => false,+ }+ }+/// `minValue` / `maxValue` / `step`, per call site. `NotchX`'s maximum is/// `notchXMax()` and therefore not constant; it is patched in by/// [`EditorWindow::slider_limits`].@@ -1061,6 +1086,32 @@ impl EditorWindow {change: impl FnOnce(&mut ProjectConfiguration) -> bool,window: &mut Window,cx: &mut Context<Self>,+ ) {+ self.edit_background_inner(true, reason, change, window, cx);+ }++ /// [`Self::edit_background`] for edits that cannot change the timeline+ /// model or its lanes -- the background tab's sliders and the+ /// animated-gradient add/remove/stop/reset edits, whose fields+ /// [`crate::editor_timeline::TimelineModel::build`] and+ /// [`crate::editor_timeline::TrackLanes::from_project`] do not read.+ fn edit_background_without_timeline(+ &mut self,+ reason: &'static str,+ change: impl FnOnce(&mut ProjectConfiguration) -> bool,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ self.edit_background_inner(false, reason, change, window, cx);+ }++ fn edit_background_inner(+ &mut self,+ rebuild_timeline: bool,+ reason: &'static str,+ change: impl FnOnce(&mut ProjectConfiguration) -> bool,+ window: &mut Window,+ cx: &mut Context<Self>,) {if !self.project_ready() {return;@@ -1076,7 +1127,11 @@ impl EditorWindow {if !self.apply_control_change(change) {return;}- self.project_changed(window, cx);+ if rebuild_timeline {+ self.project_changed(window, cx);+ } else {+ self.project_changed_without_timeline(window, cx);+ }self.remember_animated_gradient_selection(previous_animated_gradient, window, cx);self.note_sidebar_edit(reason);}@@ -1091,6 +1146,31 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,change: impl FnOnce(&mut ProjectConfiguration) -> bool,+ ) {+ self.edit_project_with_rebuild(true, reason, window, cx, change);+ }++ /// [`Self::edit_project`] for edits that cannot change the timeline model.+ pub(crate) fn edit_project_without_timeline(+ &mut self,+ reason: &'static str,+ window: &mut Window,+ cx: &mut Context<Self>,+ change: impl FnOnce(&mut ProjectConfiguration) -> bool,+ ) {+ self.edit_project_with_rebuild(false, reason, window, cx, change);+ }++ /// The shared project write. `rebuild_timeline` is true for edits that+ /// touch a field [`crate::editor_timeline::TimelineModel::build`] or+ /// [`crate::editor_timeline::TrackLanes::from_project`] reads.+ pub(crate) fn edit_project_with_rebuild(+ &mut self,+ rebuild_timeline: bool,+ reason: &'static str,+ window: &mut Window,+ cx: &mut Context<Self>,+ change: impl FnOnce(&mut ProjectConfiguration) -> bool,) {if !self.project_ready() {return;@@ -1099,7 +1179,11 @@ impl EditorWindow {if !self.apply_control_change(change) {return;}- self.project_changed(window, cx);+ if rebuild_timeline {+ self.project_changed(window, cx);+ } else {+ self.project_changed_without_timeline(window, cx);+ }self.note_project_edit(reason);}@@ -1345,7 +1429,8 @@ impl EditorWindow {cx: &mut Context<Self>,) {let base = self.notch_base();- self.edit_background(+ self.edit_background_inner(+ slider.changes_timeline_model(),"slider",|project| {let background = &mut project.background;diff --git a/apps/desktop-gpui/src/editor_sidebar/animated_gradient.rs b/apps/desktop-gpui/src/editor_sidebar/animated_gradient.rsindex 2e9256356..eeda7203a 100644--- a/apps/desktop-gpui/src/editor_sidebar/animated_gradient.rs+++ b/apps/desktop-gpui/src/editor_sidebar/animated_gradient.rs@@ -503,7 +503,7 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- self.edit_background(+ self.edit_background_without_timeline("animated-gradient-setting",|project| match &mut project.background.source {BackgroundSource::AnimatedGradient { config } => change(config),diff --git a/apps/desktop-gpui/src/editor_tabs.rs b/apps/desktop-gpui/src/editor_tabs.rsindex 1e999966a..7801a8d0f 100644--- a/apps/desktop-gpui/src/editor_tabs.rs+++ b/apps/desktop-gpui/src/editor_tabs.rs@@ -354,6 +354,22 @@ pub enum CameraSlider {}impl CameraSlider {+ /// Whether this slider writes a field+ /// [`crate::editor_timeline::TimelineModel::build`] or+ /// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match+ /// is exhaustive so a new slider has to make the choice explicitly.+ pub(crate) fn changes_timeline_model(self) -> bool {+ match self {+ Self::Size+ | Self::ZoomSize+ | Self::Rounding+ | Self::Shadow+ | Self::ShadowSize+ | Self::ShadowOpacity+ | Self::ShadowBlur => false,+ }+ }+pub fn limits(self) -> (f32, f32, f32) {match self {// `minValue={20} maxValue={80} step={0.1}` (`:3204-3206`).@@ -385,6 +401,15 @@ pub enum AudioSlider {}impl AudioSlider {+ /// Both audio sliders write levels [`TimelineModel::build`] reads; the+ /// lanes do not read audio levels. The match is exhaustive so a new+ /// slider has to make the choice explicitly.+ pub(crate) fn changes_timeline_model(self) -> bool {+ match self {+ Self::MicVolume | Self::SystemVolume => true,+ }+ }+/// `minValue={-30} maxValue={10} step={0.1}` on both (`:787-791`,/// `:806-810`).pub fn limits(self) -> (f32, f32, f32) {@@ -413,6 +438,24 @@ pub enum CursorSlider {}impl CursorSlider {+ /// Whether this slider writes a field+ /// [`crate::editor_timeline::TimelineModel::build`] or+ /// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match+ /// is exhaustive so a new slider has to make the choice explicitly.+ pub(crate) fn changes_timeline_model(self) -> bool {+ match self {+ Self::Size+ | Self::Tilt+ | Self::IdleDelay+ | Self::Tension+ | Self::Friction+ | Self::Mass+ | Self::RippleStrength+ | Self::RippleSize+ | Self::RippleDuration => false,+ }+ }+pub fn limits(self) -> (f32, f32, f32) {match self {Self::Size => (20., 300., 1.),@@ -513,6 +556,17 @@ fn set_caption_position_from(}impl CaptionSlider {+ /// Whether this slider writes a field+ /// [`crate::editor_timeline::TimelineModel::build`] or+ /// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match+ /// is exhaustive so a new slider has to make the choice explicitly.+ pub(crate) fn changes_timeline_model(self) -> bool {+ match self {+ Self::Size | Self::BackgroundOpacity | Self::FadeDuration => false,+ Self::ManualX | Self::ManualY => false,+ }+ }+pub fn limits(self) -> (f32, f32, f32) {match self {Self::Size => (12., 100., 1.),@@ -545,6 +599,20 @@ pub enum KeyboardSlider {}impl KeyboardSlider {+ /// Whether this slider writes a field+ /// [`crate::editor_timeline::TimelineModel::build`] or+ /// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match+ /// is exhaustive so a new slider has to make the choice explicitly.+ pub(crate) fn changes_timeline_model(self) -> bool {+ match self {+ Self::Size+ | Self::BackgroundOpacity+ | Self::FadeDuration+ | Self::LingerDuration+ | Self::GroupingThreshold => false,+ }+ }+pub fn limits(self) -> (f32, f32, f32) {match self {Self::Size => (12., 100., 1.),@@ -1017,7 +1085,18 @@ impl EditorWindow {cx: &mut Context<Self>,change: impl FnOnce(&mut CaptionSettings),) {- self.edit_project(reason, window, cx, |project| {+ self.set_caption_setting_inner(true, reason, window, cx, change);+ }++ fn set_caption_setting_inner(+ &mut self,+ rebuild_timeline: bool,+ reason: &'static str,+ window: &mut Window,+ cx: &mut Context<Self>,+ change: impl FnOnce(&mut CaptionSettings),+ ) {+ let apply = |project: &mut ProjectConfiguration| {with_caption_settings(project, |settings| {change(settings);// `STYLE_PRESET_KEYS` knocks the grade to "custom"@@ -1028,7 +1107,12 @@ impl EditorWindow {settings.preset = "custom".to_string();}})- });+ };+ if rebuild_timeline {+ self.edit_project(reason, window, cx, apply);+ } else {+ self.edit_project_without_timeline(reason, window, cx, apply);+ }}pub(crate) fn set_keyboard_setting(@@ -1038,9 +1122,23 @@ impl EditorWindow {cx: &mut Context<Self>,change: impl FnOnce(&mut KeyboardSettings),) {- self.edit_project(reason, window, cx, |project| {- with_keyboard_settings(project, change)- });+ self.set_keyboard_setting_inner(true, reason, window, cx, change);+ }++ fn set_keyboard_setting_inner(+ &mut self,+ rebuild_timeline: bool,+ reason: &'static str,+ window: &mut Window,+ cx: &mut Context<Self>,+ change: impl FnOnce(&mut KeyboardSettings),+ ) {+ let apply = |project: &mut ProjectConfiguration| with_keyboard_settings(project, change);+ if rebuild_timeline {+ self.edit_project(reason, window, cx, apply);+ } else {+ self.edit_project_without_timeline(reason, window, cx, apply);+ }}}@@ -1056,29 +1154,36 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- self.edit_project("camera-slider", window, cx, move |project| {- let camera = &mut project.camera;- match slider {- CameraSlider::Size => camera.size = value,- CameraSlider::ZoomSize => camera.scale_during_zoom = value / 100.,- CameraSlider::Rounding => camera.rounding = value,- CameraSlider::Shadow => camera.shadow = value,- // `...(project.camera.advancedShadow ?? {50, 18, 50})`- // (`:3253-3259`) -- the same UI fallback the background tab has.- CameraSlider::ShadowSize- | CameraSlider::ShadowOpacity- | CameraSlider::ShadowBlur => {- let mut shadow = camera.advanced_shadow.clone().unwrap_or(UI_SHADOW_FALLBACK);- match slider {- CameraSlider::ShadowSize => shadow.size = value,- CameraSlider::ShadowOpacity => shadow.opacity = value,- _ => shadow.blur = value,+ self.edit_project_with_rebuild(+ slider.changes_timeline_model(),+ "camera-slider",+ window,+ cx,+ move |project| {+ let camera = &mut project.camera;+ match slider {+ CameraSlider::Size => camera.size = value,+ CameraSlider::ZoomSize => camera.scale_during_zoom = value / 100.,+ CameraSlider::Rounding => camera.rounding = value,+ CameraSlider::Shadow => camera.shadow = value,+ // `...(project.camera.advancedShadow ?? {50, 18, 50})`+ // (`:3253-3259`) -- the same UI fallback the background tab has.+ CameraSlider::ShadowSize+ | CameraSlider::ShadowOpacity+ | CameraSlider::ShadowBlur => {+ let mut shadow =+ camera.advanced_shadow.clone().unwrap_or(UI_SHADOW_FALLBACK);+ match slider {+ CameraSlider::ShadowSize => shadow.size = value,+ CameraSlider::ShadowOpacity => shadow.opacity = value,+ _ => shadow.blur = value,+ }+ camera.advanced_shadow = Some(shadow);}- camera.advanced_shadow = Some(shadow);}- }- true- });+ true+ },+ );}pub(crate) fn apply_audio_slider(@@ -1088,13 +1193,19 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- self.edit_project("audio-slider", window, cx, move |project| {- match slider {- AudioSlider::MicVolume => project.audio.mic_volume_db = value,- AudioSlider::SystemVolume => project.audio.system_volume_db = value,- }- true- });+ self.edit_project_with_rebuild(+ slider.changes_timeline_model(),+ "audio-slider",+ window,+ cx,+ move |project| {+ match slider {+ AudioSlider::MicVolume => project.audio.mic_volume_db = value,+ AudioSlider::SystemVolume => project.audio.system_volume_db = value,+ }+ true+ },+ );}pub(crate) fn apply_cursor_slider(@@ -1104,34 +1215,40 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- self.edit_project("cursor-slider", window, cx, move |project| {- let cursor = &mut project.cursor;- match slider {- CursorSlider::Size => cursor.size = value.round() as u32,- CursorSlider::Tilt => cursor.rotation_amount = value,- // `clampIdleDelay`: `round(min(5, max(0.5, v)) * 10) / 10`- // (`:525-526`).- CursorSlider::IdleDelay => {- cursor.hide_when_idle_delay = (value.clamp(0.5, 5.) * 10.).round() / 10.- }- // `setCursorPhysics` (`:531-546`): write the field, then- // re-match the four presets and fall to `custom`.- CursorSlider::Tension | CursorSlider::Friction | CursorSlider::Mass => {- match slider {- CursorSlider::Tension => cursor.tension = value,- CursorSlider::Friction => cursor.friction = value,- _ => cursor.mass = value,+ self.edit_project_with_rebuild(+ slider.changes_timeline_model(),+ "cursor-slider",+ window,+ cx,+ move |project| {+ let cursor = &mut project.cursor;+ match slider {+ CursorSlider::Size => cursor.size = value.round() as u32,+ CursorSlider::Tilt => cursor.rotation_amount = value,+ // `clampIdleDelay`: `round(min(5, max(0.5, v)) * 10) / 10`+ // (`:525-526`).+ CursorSlider::IdleDelay => {+ cursor.hide_when_idle_delay = (value.clamp(0.5, 5.) * 10.).round() / 10.+ }+ // `setCursorPhysics` (`:531-546`): write the field, then+ // re-match the four presets and fall to `custom`.+ CursorSlider::Tension | CursorSlider::Friction | CursorSlider::Mass => {+ match slider {+ CursorSlider::Tension => cursor.tension = value,+ CursorSlider::Friction => cursor.friction = value,+ _ => cursor.mass = value,+ }+ cursor.animation_style =+ match_cursor_preset(cursor.tension, cursor.mass, cursor.friction)+ .unwrap_or(CursorAnimationStyle::Custom);}- cursor.animation_style =- match_cursor_preset(cursor.tension, cursor.mass, cursor.friction)- .unwrap_or(CursorAnimationStyle::Custom);+ CursorSlider::RippleStrength => cursor.ripple.strength = value / 100.,+ CursorSlider::RippleSize => cursor.ripple.size = value / 100.,+ CursorSlider::RippleDuration => cursor.ripple.duration = value,}- CursorSlider::RippleStrength => cursor.ripple.strength = value / 100.,- CursorSlider::RippleSize => cursor.ripple.size = value / 100.,- CursorSlider::RippleDuration => cursor.ripple.duration = value,- }- true- });+ true+ },+ );}pub(crate) fn apply_caption_slider(@@ -1141,13 +1258,21 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- self.set_caption_setting("caption-slider", window, cx, move |settings| match slider {- CaptionSlider::Size => settings.size = value.round() as u32,- CaptionSlider::BackgroundOpacity => settings.background_opacity = value.round() as u32,- CaptionSlider::FadeDuration => settings.fade_duration = value / 100.,- CaptionSlider::ManualX => set_caption_manual_center(settings, Some(value), None),- CaptionSlider::ManualY => set_caption_manual_center(settings, None, Some(value)),- });+ self.set_caption_setting_inner(+ slider.changes_timeline_model(),+ "caption-slider",+ window,+ cx,+ move |settings| match slider {+ CaptionSlider::Size => settings.size = value.round() as u32,+ CaptionSlider::BackgroundOpacity => {+ settings.background_opacity = value.round() as u32+ }+ CaptionSlider::FadeDuration => settings.fade_duration = value / 100.,+ CaptionSlider::ManualX => set_caption_manual_center(settings, Some(value), None),+ CaptionSlider::ManualY => set_caption_manual_center(settings, None, Some(value)),+ },+ );}pub(crate) fn apply_keyboard_slider(@@ -1157,7 +1282,8 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- self.set_keyboard_setting(+ self.set_keyboard_setting_inner(+ slider.changes_timeline_model(),"keyboard-slider",window,cx,@@ -3747,4 +3873,642 @@ mod tests {// The rest of the defaults come along, not just the written key.assert_eq!(keyboard_settings(&project).position, "bottom-center");}++ fn slider_model_project(timeline_segments: usize) -> ProjectConfiguration {+ let segments: Vec<serde_json::Value> = (0..timeline_segments)+ .map(|index| {+ serde_json::json!({+ "recordingSegment": 0,+ "timescale": 1.0,+ "start": index as f64,+ "end": index as f64 + 1.0,+ })+ })+ .collect();+ let config = serde_json::json!({+ "timeline": {+ "segments": segments,+ "transitions": [+ {"segmentIndex": 1, "type": "cross-fade", "duration": 0.4}+ ],+ "zoomSegments": [+ {"start": 0.0, "end": 1.0, "amount": 1.5, "mode": "auto"}+ ],+ "sceneSegments": [{"start": 0.0, "end": 1.0}],+ "maskSegments": [{+ "start": 0.0,+ "end": 1.0,+ "track": 0,+ "maskType": "sensitive",+ "center": {"x": 0.5, "y": 0.5},+ "size": {"x": 0.2, "y": 0.2}+ }],+ "textSegments": [{+ "start": 0.0,+ "end": 1.0,+ "track": 0,+ "content": "title"+ }],+ "captionSegments": [{+ "id": "caption",+ "start": 0.0,+ "end": 1.0,+ "text": "hi"+ }],+ "keyboardSegments": [{+ "id": "keyboard",+ "start": 0.0,+ "end": 1.0,+ "displayText": "A"+ }],+ "audioSegments": [{+ "start": 0.0,+ "end": 1.0,+ "track": 0,+ "path": "/tmp/none.mp3"+ }],+ "styleSegments": [{+ "start": 0.0,+ "end": 1.0,+ "track": 0,+ "enabled": true,+ "name": "Style",+ "overrides": {}+ }],+ "imageSegments": [{+ "start": 0.0,+ "end": 1.0,+ "track": 0,+ "enabled": true,+ "path": "/tmp/none.png"+ }],+ "camera3dSegments": [{"start": 0.0, "end": 1.0}]+ },+ "captions": {"settings": {"enabled": true}, "segments": []},+ "keyboard": {"settings": {"enabled": true}}+ });+ serde_json::from_value(config).expect("the slider fixture parses")+ }++ fn animated_gradient_project() -> ProjectConfiguration {+ let mut project = slider_model_project(64);+ project.background.source = cap_project::BackgroundSource::AnimatedGradient {+ config: cap_project::AnimatedGradientConfig::default(),+ };+ project+ }++ fn gradient_source() -> cap_project::BackgroundSource {+ cap_project::BackgroundSource::Gradient {+ from: [0, 0, 0],+ to: [255, 255, 255],+ angle: 90,+ noise_intensity: Some(0.2),+ noise_scale: Some(1.0),+ animated: Some(false),+ animation_speed: Some(1.0),+ }+ }++ macro_rules! slider_case {+ ($name:literal, |$project:ident| $body:block) => {+ (+ $name,+ (|$project: &mut ProjectConfiguration| $body) as fn(&mut ProjectConfiguration),+ )+ };+ ($name:literal, |$project:ident| $body:expr) => {+ (+ $name,+ (|$project: &mut ProjectConfiguration| $body) as fn(&mut ProjectConfiguration),+ )+ };+ }++ fn slider_change_cases() -> Vec<(&'static str, fn(&mut ProjectConfiguration))> {+ vec![+ slider_case!("background.blur", |project| project.background.blur = 42.),+ slider_case!("background.padding", |project| {+ project.background.padding = 12.;+ project.background.source = cap_project::BackgroundSource::Color {+ value: [255, 255, 255],+ alpha: 255,+ };+ }),+ slider_case!("background.rounding", |project| {+ project.background.rounding = 18.;+ project.background.source = cap_project::BackgroundSource::Color {+ value: [0, 0, 0],+ alpha: 255,+ };+ }),+ slider_case!("background.motion_blur", |project| {+ project.cursor.motion_blur = 0.5;+ project.screen_motion_blur = 0.5;+ }),+ slider_case!("background.border.width", |project| {+ let mut border = project.background.border.clone().unwrap_or_default();+ border.width = 8.;+ project.background.border = Some(border);+ }),+ slider_case!("background.border.opacity", |project| {+ let mut border = project.background.border.clone().unwrap_or_default();+ border.opacity = 60.;+ project.background.border = Some(border);+ }),+ slider_case!("background.notch.width", |project| {+ let mut notch = project.background.notch.unwrap_or_default();+ notch.enabled = true;+ notch.width = Some(0.2);+ project.background.notch = Some(notch);+ }),+ slider_case!("background.notch.height", |project| {+ let mut notch = project.background.notch.unwrap_or_default();+ notch.enabled = true;+ notch.height = Some(0.05);+ project.background.notch = Some(notch);+ }),+ slider_case!("background.notch.x", |project| {+ let mut notch = project.background.notch.unwrap_or_default();+ notch.enabled = true;+ notch.x = Some(0.25);+ project.background.notch = Some(notch);+ }),+ slider_case!("background.shadow", |project| project.background.shadow =+ 22.),+ slider_case!("background.advanced_shadow.size", |project| {+ project.background.advanced_shadow = Some(ShadowConfiguration {+ size: 22.,+ opacity: 50.,+ blur: 4.,+ });+ }),+ slider_case!("background.advanced_shadow.opacity", |project| {+ project.background.advanced_shadow = Some(ShadowConfiguration {+ size: 20.,+ opacity: 80.,+ blur: 4.,+ });+ }),+ slider_case!("background.advanced_shadow.blur", |project| {+ project.background.advanced_shadow = Some(ShadowConfiguration {+ size: 20.,+ opacity: 50.,+ blur: 12.,+ });+ }),+ slider_case!("background.gradient.angle", |project| {+ project.background.source = gradient_source();+ if let cap_project::BackgroundSource::Gradient { angle, .. } =+ &mut project.background.source+ {+ *angle = 45;+ }+ }),+ slider_case!("background.gradient.noise_intensity", |project| {+ project.background.source = gradient_source();+ if let cap_project::BackgroundSource::Gradient {+ noise_intensity, ..+ } = &mut project.background.source+ {+ *noise_intensity = Some(0.8);+ }+ }),+ slider_case!("background.gradient.noise_scale", |project| {+ project.background.source = gradient_source();+ if let cap_project::BackgroundSource::Gradient { noise_scale, .. } =+ &mut project.background.source+ {+ *noise_scale = Some(2.0);+ }+ }),+ slider_case!("camera.size", |project| project.camera.size = 55.),+ slider_case!("camera.zoom_size", |project| project+ .camera+ .scale_during_zoom = 1.5),+ slider_case!("camera.rounding", |project| project.camera.rounding = 18.),+ slider_case!("camera.shadow", |project| project.camera.shadow = 30.),+ slider_case!("camera.advanced_shadow.size", |project| {+ project.camera.advanced_shadow = Some(ShadowConfiguration {+ size: 22.,+ opacity: 50.,+ blur: 4.,+ });+ }),+ slider_case!("camera.advanced_shadow.opacity", |project| {+ project.camera.advanced_shadow = Some(ShadowConfiguration {+ size: 20.,+ opacity: 80.,+ blur: 4.,+ });+ }),+ slider_case!("camera.advanced_shadow.blur", |project| {+ project.camera.advanced_shadow = Some(ShadowConfiguration {+ size: 20.,+ opacity: 50.,+ blur: 12.,+ });+ }),+ slider_case!("cursor.size", |project| project.cursor.size = 2),+ slider_case!("cursor.rotation_amount", |project| project+ .cursor+ .rotation_amount =+ 15.),+ slider_case!("cursor.hide_when_idle_delay", |project| project+ .cursor+ .hide_when_idle_delay =+ 2.5),+ slider_case!("cursor.tension", |project| project.cursor.tension = 45.),+ slider_case!("cursor.friction", |project| project.cursor.friction = 45.),+ slider_case!("cursor.mass", |project| project.cursor.mass = 1.5),+ slider_case!("cursor.animation_style", |project| project+ .cursor+ .animation_style =+ CursorAnimationStyle::Custom),+ slider_case!("cursor.ripple.strength", |project| project+ .cursor+ .ripple+ .strength = 45.),+ slider_case!("cursor.ripple.size", |project| project.cursor.ripple.size =+ 45.),+ slider_case!("cursor.ripple.duration", |project| project+ .cursor+ .ripple+ .duration = 900.),+ slider_case!("caption.size", |project| project+ .captions+ .as_mut()+ .unwrap()+ .settings+ .size = 72),+ slider_case!("caption.background_opacity", |project| project+ .captions+ .as_mut()+ .unwrap()+ .settings+ .background_opacity =+ 80),+ slider_case!("caption.fade_duration", |project| project+ .captions+ .as_mut()+ .unwrap()+ .settings+ .fade_duration = 0.5),+ slider_case!("caption.preset", |project| project+ .captions+ .as_mut()+ .unwrap()+ .settings+ .preset = "custom".into()),+ slider_case!("keyboard.size", |project| project+ .keyboard+ .as_mut()+ .unwrap()+ .settings+ .size = 72),+ slider_case!("keyboard.background_opacity", |project| project+ .keyboard+ .as_mut()+ .unwrap()+ .settings+ .background_opacity =+ 80),+ slider_case!("keyboard.fade_duration", |project| project+ .keyboard+ .as_mut()+ .unwrap()+ .settings+ .fade_duration = 0.5),+ slider_case!("keyboard.linger_duration", |project| project+ .keyboard+ .as_mut()+ .unwrap()+ .settings+ .linger_duration =+ 1.5),+ slider_case!("keyboard.grouping_threshold_ms", |project| project+ .keyboard+ .as_mut()+ .unwrap()+ .settings+ .grouping_threshold_ms =+ 750.),+ ]+ }+ fn assert_timeline_model_unchanged_in(+ mut project: ProjectConfiguration,+ name: &str,+ change: impl FnOnce(&mut ProjectConfiguration),+ ) {+ use crate::editor_timeline::{TimelineModel, TrackLanes};++ let lanes_before = TrackLanes::from_project(&project, true);+ let before = TimelineModel::build_with_lanes(&project, true, true, &lanes_before);+ change(&mut project);+ let lanes_after = TrackLanes::from_project(&project, true);+ assert_eq!(+ lanes_before, lanes_after,+ "{name} must not change the track lanes"+ );+ let after = TimelineModel::build_with_lanes(&project, true, true, &lanes_after);+ assert_eq!(+ format!("{before:?}"),+ format!("{after:?}"),+ "{name} must not change the timeline model"+ );+ }++ fn assert_timeline_model_unchanged(name: &str, change: impl FnOnce(&mut ProjectConfiguration)) {+ assert_timeline_model_unchanged_in(slider_model_project(64), name, change);+ }++ fn assert_timeline_model_changes_in(+ mut project: ProjectConfiguration,+ name: &str,+ change: impl FnOnce(&mut ProjectConfiguration),+ ) {+ use crate::editor_timeline::TimelineModel;++ let before = TimelineModel::build(&project, true, true);+ change(&mut project);+ let after = TimelineModel::build(&project, true, true);+ assert_ne!(+ format!("{before:?}"),+ format!("{after:?}"),+ "{name} must change the timeline model"+ );+ }++ fn assert_timeline_model_changes(name: &str, change: impl FnOnce(&mut ProjectConfiguration)) {+ assert_timeline_model_changes_in(slider_model_project(64), name, change);+ }++ #[test]+ fn slider_edits_do_not_change_the_timeline_model() {+ for (name, change) in slider_change_cases() {+ assert_timeline_model_unchanged(name, change);+ }++ for target in [GradeTarget::Screen, GradeTarget::Camera] {+ for slider in crate::editor_color::GradeSlider::ADJUST+ .iter()+ .copied()+ .chain(std::iter::once(crate::editor_color::GradeSlider::Grain))+ {+ let target_name = match target {+ GradeTarget::Screen => "screen",+ GradeTarget::Camera => "camera",+ };+ let name = format!("grade.{target_name}.{}", slider.label());+ assert_timeline_model_unchanged(&name, move |project| {+ let grade = match target {+ GradeTarget::Screen => &mut project.color_correction.screen,+ GradeTarget::Camera => &mut project.color_correction.camera,+ };+ slider.write(grade, 0.5);+ grade.preset = "custom".into();+ });+ }+ }++ for parameter in cap_project::AnimatedGradientParameter::ALL {+ let name = format!("animated_gradient.{}", parameter.control().label);+ assert_timeline_model_unchanged_in(+ animated_gradient_project(),+ &name,+ move |project| {+ let current = {+ let cap_project::BackgroundSource::AnimatedGradient { config } =+ &project.background.source+ else {+ panic!("the fixture is an animated gradient");+ };+ parameter.get(config)+ };+ let control = parameter.control();+ let next = if current + control.step <= control.max {+ current + control.step+ } else {+ control.min + control.step+ };+ let cap_project::BackgroundSource::AnimatedGradient { config } =+ &mut project.background.source+ else {+ panic!("the fixture is an animated gradient");+ };+ parameter.set(config, next);+ },+ );+ }++ assert_timeline_model_unchanged_in(+ animated_gradient_project(),+ "animated_gradient.stop_position",+ |project| {+ let cap_project::BackgroundSource::AnimatedGradient { config } =+ &mut project.background.source+ else {+ panic!("the fixture is an animated gradient");+ };+ config.color_stops[0].position = 75.0;+ },+ );+ }++ #[test]+ fn audio_levels_still_change_the_timeline_model() {+ assert_timeline_model_changes("audio.mic_volume_db", |project| {+ project.audio.mic_volume_db = 1.5;+ });+ assert_timeline_model_changes("audio.system_volume_db", |project| {+ project.audio.system_volume_db = 1.5;+ });+ let mut camera_project = slider_model_project(64);+ camera_project+ .timeline+ .as_mut()+ .unwrap()+ .scene_segments+ .clear();+ assert_timeline_model_changes_in(camera_project, "camera.hide", |project| {+ project.camera.hide = true;+ });+ assert_timeline_model_changes("captions.settings.enabled", |project| {+ project.captions.as_mut().unwrap().settings.enabled = false;+ });+ assert_timeline_model_changes("keyboard.settings.enabled", |project| {+ project.keyboard.as_mut().unwrap().settings.enabled = false;+ });+ }++ /// Pin every variant's classification, not just the project fields the+ /// slider happens to write. A new variant still fails to compile until it+ /// picks a side; this catches flipping an existing variant without+ /// updating the routing tests.+ #[test]+ fn slider_classification_is_pinned_per_variant() {+ use crate::editor_color::GradeSlider;+ use crate::editor_sidebar::BgSlider;++ for slider in [+ BgSlider::Blur,+ BgSlider::Padding,+ BgSlider::Rounding,+ BgSlider::MotionBlur,+ BgSlider::BorderWidth,+ BgSlider::BorderOpacity,+ BgSlider::NotchWidth,+ BgSlider::NotchHeight,+ BgSlider::NotchX,+ BgSlider::Shadow,+ BgSlider::ShadowSize,+ BgSlider::ShadowOpacity,+ BgSlider::ShadowBlur,+ BgSlider::GradientAngle,+ BgSlider::GradientNoise,+ BgSlider::GradientGrain,+ ] {+ assert!(+ !slider.changes_timeline_model(),+ "background {slider:?} must not rebuild the timeline"+ );+ }++ for slider in [+ CameraSlider::Size,+ CameraSlider::ZoomSize,+ CameraSlider::Rounding,+ CameraSlider::Shadow,+ CameraSlider::ShadowSize,+ CameraSlider::ShadowOpacity,+ CameraSlider::ShadowBlur,+ ] {+ assert!(+ !slider.changes_timeline_model(),+ "camera {slider:?} must not rebuild the timeline"+ );+ }++ for slider in [AudioSlider::MicVolume, AudioSlider::SystemVolume] {+ assert!(+ slider.changes_timeline_model(),+ "audio {slider:?} must rebuild the timeline"+ );+ }++ for slider in [+ CursorSlider::Size,+ CursorSlider::Tilt,+ CursorSlider::IdleDelay,+ CursorSlider::Tension,+ CursorSlider::Friction,+ CursorSlider::Mass,+ CursorSlider::RippleStrength,+ CursorSlider::RippleSize,+ CursorSlider::RippleDuration,+ ] {+ assert!(+ !slider.changes_timeline_model(),+ "cursor {slider:?} must not rebuild the timeline"+ );+ }++ for slider in [+ CaptionSlider::Size,+ CaptionSlider::BackgroundOpacity,+ CaptionSlider::FadeDuration,+ CaptionSlider::ManualX,+ CaptionSlider::ManualY,+ ] {+ assert!(+ !slider.changes_timeline_model(),+ "caption {slider:?} must not rebuild the timeline"+ );+ }++ for slider in [+ KeyboardSlider::Size,+ KeyboardSlider::BackgroundOpacity,+ KeyboardSlider::FadeDuration,+ KeyboardSlider::LingerDuration,+ KeyboardSlider::GroupingThreshold,+ ] {+ assert!(+ !slider.changes_timeline_model(),+ "keyboard {slider:?} must not rebuild the timeline"+ );+ }++ for slider in [+ GradeSlider::Grain,+ GradeSlider::Intensity,+ GradeSlider::Exposure,+ GradeSlider::Contrast,+ GradeSlider::Saturation,+ GradeSlider::Temperature,+ GradeSlider::Tint,+ GradeSlider::Fade,+ GradeSlider::SplitTone,+ GradeSlider::Vignette,+ ] {+ assert!(+ !slider.changes_timeline_model(),+ "grade {slider:?} must not rebuild the timeline"+ );+ }+ }++ /// Times the rebuild the new route skips; the rest of `project_changed`+ /// (history, publish, save, notify) is unchanged and not measured here.+ ///+ /// The fixture is a synthetic stress case: 2,000 contiguous clips plus+ /// every track kind, not a typical project. Quote these numbers only as+ /// the cost of the skipped `TimelineModel::build_with_lanes`.+ ///+ /// `cargo test --release --manifest-path apps/desktop-gpui/Cargo.toml --bin cap-gpui -- --ignored benchmark_slider_edit_skips_timeline_rebuild --nocapture`+ #[test]+ #[ignore = "manual slider edit benchmark"]+ fn benchmark_slider_edit_skips_timeline_rebuild() {+ use std::{hint::black_box, time::Instant};++ fn median(samples: &mut [f64]) -> f64 {+ assert!(samples.len() > 1, "median needs more than one sample");+ samples.sort_by(f64::total_cmp);+ let middle = samples.len() / 2;+ if samples.len() % 2 == 0 {+ (samples[middle - 1] + samples[middle]) / 2.+ } else {+ samples[middle]+ }+ }++ use crate::editor_timeline::{TimelineModel, TrackLanes};++ let project = slider_model_project(2_000);+ let lanes = TrackLanes::from_project(&project, true);++ // Warm caches and the allocator before sampling.+ for _ in 0..3 {+ drop(black_box(TimelineModel::build_with_lanes(+ &project, true, true, &lanes,+ )));+ }++ let mut samples = Vec::new();+ for _ in 0..10 {+ let started = Instant::now();+ for _ in 0..10 {+ drop(black_box(TimelineModel::build_with_lanes(+ &project, true, true, &lanes,+ )));+ }+ samples.push(started.elapsed().as_secs_f64() * 1_000_000. / 10.);+ }++ let skipped = median(&mut samples);+ println!(+ "slider_edit timeline_segments=2000 samples=10 iterations_per_sample=10 \+ skipped_rebuild_us={skipped:.3}"+ );+ }}diff --git a/apps/desktop-gpui/src/editor_window.rs b/apps/desktop-gpui/src/editor_window.rsindex 2344d3f2b..1a85d6bce 100644--- a/apps/desktop-gpui/src/editor_window.rs+++ b/apps/desktop-gpui/src/editor_window.rs@@ -2440,14 +2440,27 @@ impl EditorWindow {self.project_changed_inner(true, window, cx);}- /// [`Self::project_changed`] for edits that only write `background.frame`.+ /// [`Self::project_changed`] for edits that cannot change the drawn+ /// timeline model.///- /// [`crate::editor_timeline::TimelineModel::build`] never reads the frame- /// or the background (the style track draws a segment's name and enabled- /// flag only), so a frame edit can skip the rebuild. The frame text fields- /// call this once per keystroke; any edit that touches a field the timeline- /// model reads must go through [`Self::project_changed`] instead.- fn project_changed_without_timeline(&mut self, window: &mut Window, cx: &mut Context<Self>) {+ /// [`crate::editor_timeline::TimelineModel::build`] reads segment arrays,+ /// track enabled flags, overlay order, audio levels, and whether a camera+ /// exists; [`crate::editor_timeline::TrackLanes::from_project`] reads the+ /// same segment and track state. Neither reads the frame, background+ /// styling, camera geometry, cursor styling, caption/keyboard styling, or+ /// color correction, so edits to those fields can skip the rebuild.+ ///+ /// The frame text fields, the classified background/camera/cursor/+ /// caption/keyboard sliders, color-grade sliders, and animated-gradient+ /// parameter/stop/add/remove/reset edits call this. Audio levels, clip+ /// volume, panel sliders, animated-gradient preset selection, and any edit+ /// that touches a field the timeline model or lanes read still go through+ /// [`Self::project_changed`].+ pub(crate) fn project_changed_without_timeline(+ &mut self,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {self.project_changed_inner(false, window, cx);}