Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

improve: clear stale cursor bind group on pooled layers; trim docs, honest benchmark

Wraient89a68d68c6c2
diff --git a/apps/desktop-gpui/examples/export-progress-coalesce-benchmark.rs b/apps/desktop-gpui/examples/export-progress-coalesce-benchmark.rs
index 5e705a968..e78675a2d 100644
--- a/apps/desktop-gpui/examples/export-progress-coalesce-benchmark.rs
+++ b/apps/desktop-gpui/examples/export-progress-coalesce-benchmark.rs
@@ -2,15 +2,14 @@
//! drain-to-latest coalescing, on the exact channel pattern used by the
//! export UI in `src/editor_export.rs`.
//!
-//! "old" reproduces the previous drain loop: one `update` + `cx.notify()`
-//! (a full editor render-tree rebuild) per progress message received.
-//! "new" is the replacement: drain to the latest message, single update +
-//! notify per 50ms wake. The producer sends at 60 msg/s for 5s in both.
+//! "old" reproduces the previous drain loop: one model update per progress
+//! message received. "new" is the replacement: drain to the latest message,
+//! single update per 50ms wake. The producer sends at 60 msg/s for 5s in both.
//!
-//! The mock update body mirrors the real one (field writes + the
-//! `"{} / {} frames"` label); `cx.notify()` itself is not measurable here,
-//! so the headline metric is update invocations: every avoided update is one
-//! avoided render-tree rebuild while the machine is encode-bound.
+//! What is measured: update invocations (exact) and the mock update body
+//! cost (field writes + the `"{} / {} frames"` label). What is not measured:
+//! `cx.notify()`'s render-tree rebuild, which runs once per update in
+//! production and is the reason fewer updates matter.
//!
//! Run: cargo run -p cap-desktop-gpui --example export-progress-coalesce-benchmark --release
@@ -119,7 +118,7 @@ fn main() {
println!("old updates: {old_updates}");
println!("new updates: {new_updates}");
println!(
- "update reduction: {:.1}x (each avoided update skips a full render-tree rebuild)",
+ "update reduction: {:.1}x",
old_updates as f64 / new_updates as f64
);
println!("final UI state old={old_final:?} new={new_final:?} (identical)");
diff --git a/crates/rendering/src/layers/cursor.rs b/crates/rendering/src/layers/cursor.rs
index a2d16dd99..abfb3ac70 100644
--- a/crates/rendering/src/layers/cursor.rs
+++ b/crates/rendering/src/layers/cursor.rs
@@ -453,6 +453,7 @@ impl CursorLayer {
let time_s = segment_frames.recording_time;
let Some(interpolated_cursor) = &uniforms.interpolated_cursor else {
+ self.bind_group = None;
return;
};
@@ -562,6 +563,7 @@ impl CursorLayer {
}
let Some(tex) = self.cursors.get(&interpolated_cursor.cursor_id) else {
error!("Cursor {:?} not found!", interpolated_cursor.cursor_id);
+ self.bind_group = None;
return;
};
tex
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 59759c674..3341b098d 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -1155,15 +1155,8 @@ fn take_pooled_layers(device: &wgpu::Device, key: &str) -> Option<RendererLayers
Some(pool.swap_remove(index).2)
}
-/// Take a set of GPU layer pipelines previously returned to the pool for
-/// `key` on this device, with per-frame state reset. Returns `None` when the
-/// pool holds nothing reusable, in which case the caller should build a fresh
-/// [`RendererLayers`] and [`return_reusable_layers`] it afterwards.
-///
-/// This is the same mechanism the export path uses to avoid paying the
-/// ~0.25-0.5 s layer-pipeline build cost on every render; it is also suitable
-/// for repeated single-frame renders (e.g. export previews) that share one
-/// long-lived device.
+/// Layers are never shared across keys: they cache per-project assets under
+/// ids that are only unique within a recording.
pub fn take_reusable_layers(device: &wgpu::Device, key: &str) -> Option<RendererLayers> {
take_pooled_layers(device, key).map(|mut layers| {
layers.reset_frame_state();
@@ -1171,9 +1164,8 @@ pub fn take_reusable_layers(device: &wgpu::Device, key: &str) -> Option<Renderer
})
}
-/// Return layer pipelines to the pool so the next render with the same `key`
-/// on the same device can skip pipeline compilation. Only call after a clean
-/// render: a failed render may leave layer state behind.
+/// Only return layers after a clean render; a failed render may leave layer
+/// state behind.
pub fn return_reusable_layers(device: wgpu::Device, key: String, layers: RendererLayers) {
return_pooled_layers(device, key, layers);
}