Skip to content

perf(gpui): resolve complex shape overlays in one pass with A/B benchmarks - #3945

Open
himanshu748 wants to merge 11 commits into
CapSoftware:mainfrom
himanshu748:perf/gpui-shape-overlay-order
Open

himanshu748 wants to merge 11 commits into
CapSoftware:mainfrom
himanshu748:perf/gpui-shape-overlay-order

Conversation

@himanshu748

@himanshu748 himanshu748 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The native GPUI Studio editor resolves visible shape stacking on every redraw and pointer move. Previously, each overlay shape track rescanned every shape segment to collect its active shapes, while resolving the overlay stacking order used repeated Vec::contains membership checks. This makes the work quadratic as a project gains tracks.

This PR makes that hot path scale with the number of shapes and tracks:

  • Resolve large saved overlay stacks with membership sets while retaining the existing small-project fast path (24 or fewer tracks), order, de-duplication, and compatibility with stale saved entries.
  • Group active shape indices in one scan using compact linked index lists (no per-track heap vectors), then flatten in the exact paint/hit-test stacking order. Small projects keep the original direct-scan path.
  • Route GPUI's EditorWindow::visible_shape_order through the shared project implementation, affecting frame redraw and pointer hit-testing without changing scene semantics.
  • Add regression tests comparing the old and new ordering with duplicate/stale tracks, disabled shapes, sparse track IDs, boundary timestamps, NaNs, and both custom/default order.
  • Add a self-contained, interleaved A/B benchmark comparing the previous end-to-end algorithms with this branch's implementation for 1, 16, 64, 128, and 256 shape tracks.

Why this is a meaningful optimization

Before: active shape ordering rescans N shapes for each of T shape tracks, O(N × T); resolving the stack is O(T²).

After: active shape ordering performs one O(N) scan, plus O(T) bucket setup/flattening; saved stack membership checks are O(T) expected. Shape-track counts of 16 or fewer, and scenes with at most 32,768 shape-track comparisons, retain the direct-scan path.

The implementation keeps the output indices byte-for-byte equivalent to the old ordering, including per-track source order and reverse-of-stack paint order.

Native Rust measurements, including review regression cases (November 8, 2026)

Environment: isolated Vercel Linux x86-64 sandbox, 4 vCPUs, 8 GB RAM, Rust 1.95.0, release-optimized cap-project. The checked-in benchmark compares the original and optimized Rust algorithms in the same executable, asserts identical indices, and alternates nine A/B timing rounds. The figures below are medians from seven independent benchmark processes on the reviewed implementation.

Shape tracks Shapes Old median (µs) New median (µs) Speedup
1 1,024 5.10 5.01 1.01×
1 8,193 44.30 44.21 1.01×
8 8,256 115.54 104.13 1.12×
9 8,280 124.76 109.58 1.13×
12 9,216 173.26 144.37 1.17×
16 512 13.20 11.23 1.17×
16 9,600 236.36 200.45 1.18×
17 68 2.21 2.08 1.06×
17 1,088 26.75 22.28 1.20×
64 2,048 143.24 56.65 2.54×
128 4,096 559.21 116.58 4.81×
256 4,096 1,071.31 136.69 7.84×

At 256 tracks, all seven process-level speedups were between 7.64× and 8.03×. The 1, 8, 9, 12, 16, and 17-track cases are explicit regression checks following the Greptile/Codex reviews. The revised dispatch preserves the original direct scans for up to 16 shape tracks or up to 32,768 shape-track comparisons; larger scenes use grouped traversal.

Validation

  • cargo +1.95.0 test --release --locked -p cap-project --lib: 293 passed, 0 failed, 7 ignored.
  • cargo +1.95.0 fmt --all -- --check: passed.
  • All benchmark old/new ordering assertions passed across workloads and process runs.
  • Full desktop frame-time/FPS improvement is not established by these microbenchmarks. The speedup is for shape-order computation only.
  • Review follow-up: Greptile and Codex feedback addressed in fd509ec.

Reproduce the benchmark

cargo run --release -p cap-project --example gpui_shape_order_benchmark
cargo test -p cap-project overlay_frame_order_tests
cd apps/desktop-gpui && cargo check -p cap-desktop-gpui

The benchmark prints JSON rows with baseline_p50_us, optimized_p50_us and speedup, with nine interleaved timing samples per case and a correctness assertion before timing.

This targets an independent GPUI code path and intentionally does not overlap the separate GPUI renderer/scene patch work in #3886/#3887.

AI assistance disclosure: Code changes and the benchmark harness were developed with AI assistance. The performance figures above come from actual compiled native Rust A/B runs, not model estimates; correctness was verified with tests.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issues were found.

Summary

The PR shares shape ordering between GPUI and the project code, uses membership sets for large overlay stacks, and groups active shapes in one pass for larger scenes.

  • Large overlay lists keep their saved track order without repeated membership scans.
  • Large shape stacks get their visible order from one scan.

Reviews (6) · Last reviewed commit: "perf(gpui): protect sparse shape timelin..." · Reviewed by Greptile

@vercel

vercel Bot commented Nov 8, 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 November 8, 2026 08:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T09:15:45.764052Z fd509ec Manual request
ℹ️ 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 thread crates/project/src/configuration.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb24d25528

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/project/src/configuration.rs Resolved

Copy link
Copy Markdown
Contributor Author

Both review findings are addressed in commit fd509ec, and the two prior threads have been resolved.

  • Greptile: Added regression tests for the grouped path above both cutoffs, sparse track IDs, custom stacking, inactive shapes, and boundary timestamps.
  • Codex: Preserved direct scanning for up to 16 shape tracks (or up to 32,768 shape-track comparisons). The previously regressing cases now match or outperform baseline in seven native Rust A/B runs.
  • Verification: 293 cap-project tests passed, Rust formatting passed, and the 256-track / 4,096-shape benchmark showed 7.84× median speedup across seven independent processes. This measures shape ordering, not whole-frame FPS.

Could you please review the latest head fd509ec10322b869a7e00c43688ed07f914efed2?

@codex review
@greptile review

Note: Several unrelated CI checks have been failing at dependency download/setup with HTTP 504 errors rather than a code/test failure.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: fd509ec103

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor Author

CI investigation for the latest head fd509ec (run 42465538549, attempt 2): all applicable checks passed except Build GPUI Desktop (x86_64-apple-darwin, macos-26-intel) (job 128906351300). Windows, Linux and Apple Silicon desktop builds, Rust tests, Clippy, typecheck, lint, format, and the separate perf/reliability workflows succeeded.

I checked the first attempt's Intel job log: it failed in node scripts/setup.js downloading native-deps-x86_64-darwin-apple.tar.xz, with HTTP 504 from GitHub releases. Attempt 2 passed Run setup and Prepare GPUI dependency, then stopped during Test GPUI desktop after about 65 minutes. The current job's log download is returning a BlobNotFound error via the GitHub API, so I can't yet distinguish a test/build problem from a runner termination or timeout.

Could someone with access to the Intel runner's attempt-2 logs/annotations check the final output for job 128906351300? I don't want to alter production code or loosen coverage without a reproducible code-related failure. Thanks!

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