Skip to content

perf: skip frame clones for unchanged retained graphics - #4672

Merged
JJLiebig merged 1 commit into
herdrdev:masterfrom
minatoaquaMK2:codex/perf-retained-graphics
Sep 27, 2026
Merged

JJLiebig merged 1 commit into
herdrdev:masterfrom
minatoaquaMK2:codex/perf-retained-graphics

Conversation

@minatoaquaMK2

@minatoaquaMK2 minatoaquaMK2 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Retained surfaces containing images are deep-cloned even when nothing changed and no update will be sent. Check updated pane geometry and graphics before cloning the frame; preserve upload reuse and commit-after-success behavior.

Release builds on Apple M3 / 24 GiB, macOS 27.0, Rust 1.96.1; medians of three serial runs with alternating baseline/candidate order, compared with upstream fff6c820. Time reduction = (before − after) / before × 100%. Negative values indicate increased time. Geometry is fixed at 80×24; the static-image cases change surrounding text, not image pixels.

Retained scenario / panes Before (µs) After (µs) Time reduction
text / 1 8.417 8.292 1.49%
text / 15 36.125 36.250 -0.35%
static image + text / 1 98.209 92.209 6.11%
static image + text / 15 132.333 127.750 3.46%
unchanged image / 1 38.250 1.625 95.75%
unchanged image / 15 52.125 13.125 74.82%

Reproduce: just bench-retained-graphics. Tests cover clean/hidden-pane wakes and reuse of uploaded pixels on the next real update. Native just ci, just docs-contract-test, and GitHub Linux/macOS/Windows CI passed.

The broader just bench-render-scale hits the same existing CoW-source prerequisite failure on this Mac for baseline and candidate; the supported retained-graphics profile above passes.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4765b275-3688-4bc8-9805-ce64d7843ace

📥 Commits

Reviewing files that changed from the base of the PR and between 6502492 and 627f3f7.

📒 Files selected for processing (4)
  • justfile
  • src/server/client_shell_graphics.rs
  • src/server/headless/retained_surface.rs
  • src/server/headless/tests/pane_graphics.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Retained graphics collection now accepts pane records directly. The update path skips constructing a patched surface when no row, cursor, metadata, or graphics changes exist. Tests cover unchanged graphics, later text updates, and text, image, and unchanged-image profile scenarios. A new justfile target runs the retained-graphics profile.

Suggested reviewers: ogulcancelik

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 627f3

No actionable merge-blocking issue remains; the unchanged-graphics path preserves the revision needed for the next real update.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 627f3

The reviewed path preserves per-client pane filtering and commits delivery state only after a successful send. No new exposure was identified, although broader security coverage is incomplete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The parameter change does not establish a new cross-client input path: the caller derives the slice from the recipient’s retained surface and supplies that client’s collection context.

Trust Boundaries and Controls

  • observed — Pane identity is parsed and checked against the target workspace before graphics collection proceeds.

Resilience and Maintainability Implications

  • observed — Candidate graphics delivery state is not assigned to the client on the inspected serialization or send-failure paths; assignment occurs in the successful-send branch.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: avoiding frame clones when retained graphics are unchanged.
Description check ✅ Passed The description directly explains the optimization, preserved behavior, benchmark results, and validation performed for the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kangal-bot

Copy link
Copy Markdown
Collaborator

@coderabbitai review
@greptileai

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Optimizes graphics rendering to skip unnecessary frame clones.

The PR appears safe to merge; no outstanding or new actionable findings were identified.

Summary

The PR avoids cloning a retained frame when an image-bearing surface has no update to send.

  • Graphics collection now uses the updated panes before the no-op check; frame cloning and patch application happen only for an update that proceeds.
  • Tests cover unchanged wakes and upload reuse, and a benchmark recipe profiles the retained graphics cases.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Collect dirty pane state] --> B[Build updated panes and patch]
  B --> C[Collect retained graphics if needed]
  C --> D{Rows, cursor, metadata, or graphics changed?}
  D -- No --> E[Keep committed surface and delivery cache]
  D -- Yes --> F[Clone surface and apply patch]
  F --> G[Send update]
  G -- Success --> H[Commit surface and delivery cache]
Loading

Reviews (4) · Last reviewed commit: "perf: skip frame clones for unchanged re..."

@JJLiebig
JJLiebig force-pushed the codex/perf-retained-graphics branch from ec3d5c8 to 90261e0 Compare September 27, 2026 19:05
@JJLiebig

Copy link
Copy Markdown
Collaborator

@greptileai

JJLiebig
JJLiebig previously approved these changes Sep 27, 2026

@JJLiebig JJLiebig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rebased onto current master (21d71a03); final head is clean (Linux/macOS/Windows CI green). One conflict in render_scale_profile_retained_graphics was resolved by keeping master's newer offscreen scenario (#4686) and folding this PR's unchanged-image scenario into the same image list, so both remain covered.

The retained path now computes the graphics delta and applies pane metadata before cloning the frame, and only clones when an update will actually be sent; upload reuse and commit-after-success are preserved (covered by the new test, which also verifies the next real update still reuses uploaded pixels).

Windows benchmark (x86_64-pc-windows-msvc, rustc 1.96.1, release, median of ~100 samples, just bench-retained-graphics), retained path, unchanged image before -> after:

image scenario / panes before after cut
unchanged-image / 1 56.2 us 2.3 us 95.9%
unchanged-image / 15 78.2 us 15.1 us 80.7%

Other retained scenarios (text, visible image, offscreen image) are unchanged within noise.

Approving.

@JJLiebig
JJLiebig force-pushed the codex/perf-retained-graphics branch from 90261e0 to 105415f Compare September 27, 2026 19:19
@JJLiebig

Copy link
Copy Markdown
Collaborator

@greptileai

@JJLiebig

Copy link
Copy Markdown
Collaborator

@greptileai

@JJLiebig

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@JJLiebig JJLiebig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rebased onto master after #4669 and #4670 landed (6502492f); the shared justfile hunks were reconciled so all three bench recipes remain. The earlier conflict resolution in render_scale_profile_retained_graphics is intact: master's offscreen scenario and this PR's unchanged-image scenario are both covered.

Final head 627f3f7f is green on Linux/macOS/Windows + Windows ConPTY, with Greptile and a full CodeRabbit review on this head. Approving.

@JJLiebig
JJLiebig merged commit 87c08c6 into herdrdev:master Sep 27, 2026
7 checks passed
abhijit-s pushed a commit to abhijit-s/herdr that referenced this pull request Sep 30, 2026
Merges 46 upstream commits spanning stable releases v0.9.2 and v0.9.3:
multiple prefix keys (herdrdev#4653), self-reported agent resume commands
(herdrdev#4687), Go To workspace-grouped navigator rows (herdrdev#4384), clear_pane
keybinding (herdrdev#4383), non-interactive machine status/reconnect with SSH
MFA (herdrdev#3763), interactive machine add session picker (herdrdev#4204, herdrdev#4678),
mouse events on terminal session control (herdrdev#4685), staggered agent
restarts (herdrdev#4102), SSH compression (herdrdev#4340), row-shift scrolling
(herdrdev#4711), TERM_PROGRAM identity (herdrdev#4104), PowerShell 7 default on
Windows (herdrdev#4297), tab-close confirmation (herdrdev#4379, herdrdev#4409), full event
subscription bursts (herdrdev#4178, herdrdev#4225), SIGWINCH color refresh (herdrdev#4349),
saved-layout shutdown survival (herdrdev#4320), stray-Escape click fix
(herdrdev#3480), first-task-done detection (herdrdev#3338, herdrdev#3990, herdrdev#3916), CPU/perf
work across navigator/splits/named-targets/event-batching (herdrdev#4506,
herdrdev#4546, herdrdev#4426, herdrdev#4669, herdrdev#4670, herdrdev#4671, herdrdev#4672), synchronized-frame tearing
and cursor flicker fixes (herdrdev#2968, herdrdev#4303), API socket transient-error
resilience (herdrdev#4601), async worktree git lookups (herdrdev#4492), worktree-open
workspace-takeover fix (herdrdev#4293), SSH agent forwarding after reconnect
(herdrdev#1931, herdrdev#4252), OpenCode V1 subagent status (herdrdev#1362, herdrdev#4240), Codex
idle/mention/interrupt-key detection (herdrdev#4507, herdrdev#4196), Kiro/Grok
detection fixes (herdrdev#4203, herdrdev#4372, herdrdev#4333), Droid scrollback clears
(herdrdev#4432), copy-mode-stays-active fix (herdrdev#3812, herdrdev#4281), Ctrl+Shift+letter
fix (herdrdev#4581, herdrdev#4597), split mouse-report fix (herdrdev#4630), several Windows
paste/mouse-capture/clipboard/detection fixes (herdrdev#4251, herdrdev#4284, herdrdev#4470,
herdrdev#4314, herdrdev#4313, herdrdev#4579, herdrdev#4309), navigator search/highlight fixes (herdrdev#4300,
herdrdev#4408, herdrdev#4273, herdrdev#4535, herdrdev#4355), session-attach-without-terminal error
(herdrdev#4393), socket error request-ID preservation (herdrdev#4344), plugin install
option ordering (herdrdev#4446), Windows host color detection (herdrdev#1530, herdrdev#4369),
post-update saved-machine summary (herdrdev#4722), a hotfix for Escape-prefixed
terminal key bindings (herdrdev#4759) and pinned Windows ConPTY bundling
(herdrdev#4760), Windows same-user cross-elevation attach (herdrdev#4777), and the
libghostty-vt binding extraction into a ghostty-vt workspace crate
(herdrdev#4661).

Also fixes two merge seam breaks: overlays.rs combines the fork's
rounded_borders threading with upstream's per-client prefix-label
onboarding overlay, and the fork's command_palette test file is
updated for the new Vec<KeyCombo> prefix representation and the
BindingConfig::one constructor introduced by the multi-prefix-key
feature.

refs upstream herdrdev/herdr@331775c3
maciejul pushed a commit to maciejul/herdr-supercharged that referenced this pull request Oct 28, 2026
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.

3 participants