Skip to content

perf(gpui): update freehand stroke bounds incrementally - #3341

Open
himanshu748 wants to merge 2 commits into
CapSoftware:mainfrom
himanshu748:perf/gpui-freehand-annotation-drag
Open

himanshu748 wants to merge 2 commits into
CapSoftware:mainfrom
himanshu748:perf/gpui-freehand-annotation-drag

Conversation

@himanshu748

@himanshu748 himanshu748 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Growing a freehand screenshot annotation currently rescans every stored point whenever a new sample passes the 2px spacing threshold. Keep the active gesture's raw minima and maxima instead, so maintaining bounds visits each accepted sample once. The same points, spacing rule and final normalization remain in use; retaining raw extrema avoids rounding drift from reconstructing a maximum as x + width.

The included ignored benchmark compares complete sample ingestion against the previous full scan, including annotation/point allocation and cleanup. It performs two warmups and nine alternating before/after measurements and reports medians. On Linux x86_64 (KVM, AMD EPYC 7763), using rustc 1.99.1 with opt-level 3, thin LTO and one codegen unit, an extracted-source harness using the real cap_project::Annotation measured:

Samples in one stroke Previous ingestion Incremental ingestion
8 0.206 µs 0.149 µs
32 0.992 µs 0.305 µs
256 34.587 µs 1.236 µs
2,048 2.041 ms 8.473 µs
8,192 32.201 ms 33.824 µs

These are accumulated CPU costs for ingesting an entire stroke, not per-frame or end-to-end drawing latency. Path generation, tessellation, paint and final normalization are outside the timed region. Independent measurements in three processes, including duplicate and subthreshold events, corroborated the scaling.

Validation:

  • Five source regression tests pass in both debug and release in the isolated harness. They compare each update with the previous full scan and cover rejected points, exact spacing, reversals, flat strokes, raw-extrema rounding, empty/preloaded samples and nonfinite coordinates. Raw sample bits match exactly; geometry comparisons treat signed zeros and NaN payloads as equivalent.
  • An additional 10,000 arbitrary-f64 sequences pass differential validation in debug and release.
  • The ignored source benchmark passes; extracted production-module Clippy passes with --lib --no-deps -- -D warnings.
  • Rust formatting and git diff --check pass.
  • The full native check initially stopped on uncached jxl-oxide, resolved with a locked Linux dependency fetch. The restarted full check was then interrupted (exit 130) after a system probe confirmed missing ALSA development files. A focused cargo check -p alsa-sys --locked --offline exited 101 because alsa.pc is unavailable. Full native GPUI compilation and GUI execution remain unverified locally; no macOS execution claim is made. The local GPUI dependency checkout also predates two current preparation patches, so a configured checkout or CI must perform the native validation.

Reproduce the committed tests and benchmark in a configured native checkout:

cargo test --manifest-path apps/desktop-gpui/Cargo.toml -p cap-desktop-gpui --bin cap-gpui freehand_bounds
cargo test --manifest-path apps/desktop-gpui/Cargo.toml -p cap-desktop-gpui --bin cap-gpui --release benchmark_freehand_bounds -- --ignored --nocapture

Native CI on 857021707dd2dc029960c8b4195113071bc3389c: all five freehand_bounds regressions pass on Linux (1,553 app tests), Apple Silicon (1,478), Windows (1,437), and Intel macOS (1,473), with zero failures. The benchmark is intentionally ignored by CI; the measurements above remain local isolated-harness results. CI tested merge 299d5760935d600e2ef2a691b556ca77a127fac1, containing this exact head and base f6046f1.

All five Actions workflows completed successfully: CI, Engine verify, Verify recording, Perf budget, and Linux desktop reliability (GNOME, NixOS, niri and Hyprland). Both GitHub-required checks, Engine verify and Verify recording, pass. Vercel's two deployment statuses require maintainer authorization and are separate from code validation. No manual GUI session was performed locally.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge.

Summary

Freehand strokes now keep raw minima and maxima instead of rescanning every stored point after each accepted sample.

  • Freehand strokes update their bounds as each point arrives.

Reviews (1) · Last reviewed commit: "perf(gpui): update freehand stroke bound..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 26, 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 26, 2026 07:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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-26T07:41:38.792456Z
We couldn’t complete this review. Comment @codex review to try again.
8570217 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.

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