Skip to content

perf(gpui): avoid whole-timeline copies during clip trim previews - #3439

Open
himanshu748 wants to merge 2 commits into
CapSoftware:mainfrom
himanshu748:perf/gpui-clip-preview-data
Open

himanshu748 wants to merge 2 commits into
CapSoftware:mainfrom
himanshu748:perf/gpui-clip-preview-data

Conversation

@himanshu748

@himanshu748 himanshu748 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Dragging a clip edge and playing its release animation currently clone the entire timeline on each redraw, including unrelated captions, keyboard events, overlays and waveform-reference vectors. Preparing the preview therefore gets more expensive as those other tracks grow.

Prepare only the clip vector and trim gap, then borrow the unchanged timeline through SegmentUi. Clip rows, selection rendering and speed controls use the same preview slice. The existing trim/source-range and easing calculations are unchanged. There is no cache to invalidate, and idle/draft frames do not gain a clock read.

Measurements

These are isolated preview preparation plus result destruction, not GPUI painting, frame rate, decoding or end-to-end input latency. Synthetic prebuilt models use the same fixture helpers as the committed ignored benchmark. Fixture construction is outside the timed region.

Linux x86-64, AMD EPYC 7763, rustc 1.99.1; optimized with opt-level=3, one codegen unit, no LTO. Each of three processes runs 10 warmup pairs and 31 alternating paired samples; batches contain 128 preparations, or 16 for the 10,000-caption cases. Values below are medians of the three process medians, for owned long labels during an active end trim.

Clips Captions Before (µs) After (µs)
1 0 0.153 0.071
24 0 0.704 0.622
200 0 5.839 5.545
24 1,000 21.810 0.606
200 1,000 27.597 5.585
24 10,000 208.753 0.609
200 10,000 214.703 5.396

For each caption count, keyboard events = captions / 4; each of text, image, style, mask and audio overlays = captions / 100. Nonempty caption cases also contain one zoom, scene and 3D segment. These are explicit scaling fixtures, not estimates of typical project sizes.

The full matrix also covers static and short labels, animation at 90 ms, and idle. The 24-clip/1,000-caption owned-label animation measured 22.015 → 0.553 µs. Small cases have limited benefit: the 200-clip/no-caption short-label trim measured 3.225 → 3.233 µs (about 0.2% slower, with per-process before/after ratios 0.997–1.068). Idle is a few-nanosecond noise control; no idle speedup is claimed.

A separate allocation-counting binary measured the 24-clip/1,000-caption trim at 16 → 2 allocations and 138,688 → 2,880 requested bytes. Its animation uses 15 → 1 allocations. Allocation counters are absent from the timing binary. These are requested bytes, not resident or retained memory; waveform samples were already shared and are not deep-copied by either version.

The isolated harness extracts the baseline from 8dd141d17ea2dd592f326fdb3358f798e3c7f8ba and the changed production methods/types. It uses current project types and GPUI's actual SharedString representation with SmolStr 0.3.6. Unused editor fields and string traits are omitted; the never-dereferenced waveform-path referent is a stand-in while its Arc clone/drop operations remain. Both paths receive the same deterministic time. This is not a full native build.

Correctness and reproduction

  • Isolated differential checks pass for 27 project/label fixtures, each with 18 draft and 12 animation/idle/missing-input cases, plus speed/overlap/hold cases. They compare complete reconstructed view data, exact clip-position bits, source metadata, trim gaps and shared data identities, and verify the base model is unchanged.
  • Four Linux GPUI regressions cover complete draft/animation views, missing inputs, lazy clock behavior, and rendering rows with speed controls. The rendering test is smoke coverage, not a pixel-equivalence assertion.
  • A committed ignored benchmark contains the same input matrix and paired methodology. On a Linux development environment with Cap's native dependencies:
cd apps/desktop-gpui
cargo test --bin cap-gpui editor_window::tests::clip_preview -- --test-threads=1
cargo test --release --bin cap-gpui editor_window::tests::clip_preview::benchmark_clip_preview_preparation -- --ignored --nocapture --test-threads=1

Repeat the benchmark in three processes to compare medians. The native release profile uses thin LTO, unlike the isolated measurements above, so its timings may differ.

Formatting and diff checks pass. Local native application checking was interrupted after confirming the missing ALSA prerequisite; a focused alsa-sys check fails because pkg-config cannot find alsa.pc. The four native GPUI tests and native benchmark have not been run locally. Native CI, manual GUI interaction, pixel comparisons and end-to-end latency measurements remain outstanding at draft creation.

RetriggerView in GreptileConfidence Score: 4/5

Fix the lifetime mismatch in row_selected before merging.

Findings

  1. P1 Native app cannot build ▶
Fix with agent prompt
### Issue 1
apps/desktop-gpui/src/editor_timeline.rs:1854-1855
`row_selected` accepts `model: &TimelineModel`, but the new call to `self.segments_for` requires `model: &'a TimelineModel`. The input does not promise that lifetime, so this fails to compile with an explicit-lifetime-required error. Change the parameter to `model: &'a TimelineModel`, or let `segments_for` borrow both inputs for a shorter shared lifetime.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Replaces whole-timeline copies with a clip-only preview during trimming and release animation.

  • Clip trims show a preview without copying unrelated timeline tracks.

Reviews (1) · Last reviewed commit: "test(gpui): render clip preview smoke te..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

@himanshu748 is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

@himanshu748
himanshu748 marked this pull request as ready for review October 27, 2026 01:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-27T01:52:11.425647Z
We couldn’t complete this review. Comment @codex review to try again.
3a5df9c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment on lines +1854 to +1855
&& self
.segments_for(model, row)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Native app cannot build

row_selected accepts model: &TimelineModel, but the new call to self.segments_for requires model: &'a TimelineModel. The input does not promise that lifetime, so this fails to compile with an explicit-lifetime-required error. Change the parameter to model: &'a TimelineModel, or let segments_for borrow both inputs for a shorter shared lifetime.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/src/editor_timeline.rs
Line: 1854-1855

Comment:
**Native app cannot build**

`row_selected` accepts `model: &TimelineModel`, but the new call to `self.segments_for` requires `model: &'a TimelineModel`. The input does not promise that lifetime, so this fails to compile with an explicit-lifetime-required error. Change the parameter to `model: &'a TimelineModel`, or let `segments_for` borrow both inputs for a shorter shared lifetime.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant