Skip to content

perf: use keyed terminal lookup for named targets - #4669

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

JJLiebig merged 1 commit into
herdrdev:masterfrom
minatoaquaMK2:codex/perf-terminal-targets

Conversation

@minatoaquaMK2

@minatoaquaMK2 minatoaquaMK2 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Named terminal and agent lookup scans the terminal registry for every pane candidate. Use borrowed string keys in the existing HashMap to reduce that join from O(P×T) to expected O(P), preserving target precedence, pane order, detached-terminal exclusion and ambiguity handling.

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%.

Panes Terminal name (µs), before → after Time reduction Agent name (µs), before → after Time reduction
15 5.436 → 1.938 64.35% 4.421 → 1.079 75.59%
128 295.406 → 13.499 95.43% 275.303 → 7.372 97.32%
512 3808.354 → 54.401 98.57% 3682.549 → 30.925 99.16%

Reproduce: just bench-terminal-targets. Tests cover borrowed-key lookup after serialization and adversarial pane/tab identities. Native just ci, just docs-contract-test, and GitHub Linux/macOS/Windows CI passed.

@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.

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • ai-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c44505f8-a1d6-429e-b852-ec38a949c660

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 61b42f6e-ffe5-422e-8d1c-513114fd964b

📥 Commits

Reviewing files that changed from the base of the PR and between fff6c82 and 623fbbe.

📒 Files selected for processing (3)
  • justfile
  • src/app/terminal_targets.rs
  • src/terminal/id.rs

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


📝 Walkthrough

Walkthrough

Terminal IDs now support borrowed string lookups in maps. Terminal target matching and validation retrieve terminals directly by ID. Added tests cover resolution after pane and tab reordering, detached terminals, shared-name ambiguity, and lookup profiling. A justfile recipe runs the ignored profile test in release mode.

Suggested reviewers: ogulcancelik

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 623fb

The terminal lookup optimization is mergeable after normal checks; no actionable risk remains identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: using keyed terminal lookup to improve named-target performance.
Description check ✅ Passed The description directly explains the lookup optimization, preserved behavior, benchmark results, test coverage, and validation status.
Full details: Docstring Coverage

Explanation

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


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 terminal target lookup with keyed access.

The PR appears safe to merge; no actionable issue was identified in its changes.

Summary

The PR replaces repeated terminal-registry scans with borrowed-key lookups for named terminal and agent targets.

  • Adds tests for restored terminal IDs, reordered pane identities, ambiguity, and detached-terminal exclusion.
  • Adds an opt-in scaling profile.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Input[Target string] --> Panes[Enumerate attached panes]
  Panes --> Lookup[Look up terminal by borrowed ID]
  Lookup --> Match[Match agent name or label]
  Match --> Result[Resolve one, report ambiguity, or return not found]
Loading

Reviews (3) · Last reviewed commit: "perf: use keyed terminal lookup for name..."

@JJLiebig
JJLiebig force-pushed the codex/perf-terminal-targets branch from 623fbbe to 41f3da9 Compare September 27, 2026 19:05
@JJLiebig

Copy link
Copy Markdown
Collaborator

@greptileai

@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).

The Borrow<str> impl is sound: TerminalId is a String newtype whose derived Hash/Eq delegate to str, so terminals.get(id.as_str()) resolves the same entry that was inserted as TerminalId. The three converted lookups keep target precedence, pane order, detached-terminal exclusion and ambiguity handling, which the new tests exercise.

Windows benchmark (x86_64-pc-windows-msvc, rustc 1.96.1, release, median of 7 samples, just bench-terminal-targets), before -> after:

panes terminal name agent name
1 0.384 -> 0.360 us 0.285 -> 0.223 us
15 6.999 -> 2.643 us (-62%) 5.745 -> 1.501 us (-74%)
128 346.4 -> 20.6 us (-94%) 339.5 -> 12.7 us (-96%)
512 4846.5 -> 88.7 us (-98%) 4886.0 -> 49.2 us (-99%)

Note on the Greptile summary: it flags agent-session restore / configured-shell reporting, but neither is in this PR's diff (3 files: justfile, src/app/terminal_targets.rs, src/terminal/id.rs). Those behaviors come from unrelated master commits that entered the compare range after the rebase; there are no inline findings on this change.

Approving.

@JJLiebig
JJLiebig force-pushed the codex/perf-terminal-targets branch from 41f3da9 to ac6fd02 Compare September 27, 2026 19:19
@JJLiebig

Copy link
Copy Markdown
Collaborator

@greptileai

@JJLiebig
JJLiebig merged commit 7945e91 into herdrdev:master Sep 27, 2026
7 checks passed
colangelo pushed a commit to colangelo/herdr-max that referenced this pull request Sep 29, 2026
(cherry picked from commit 7945e91)

ported from upstream 7945e91: the fork has no AppPolicy, so the new terminal_targets.rs test builds its App with the fork's App::new(&config, true, ...) signature.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr/issues/124
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
hdosys added a commit to hdosys/herdr-ext that referenced this pull request Oct 1, 2026
Preserve the existing fork on an isolated migration branch while importing three independently verified v0.9.2 changes. Adapt the API fairness fixtures to retain the existing stream_active contract.

Upstream sources: 7945e91, 6502492, c210c95.

Refs herdrdev#4669, herdrdev#4670, herdrdev#4671

Co-authored-by: Eric Yue <jiacheng.yue@foxmail.com>
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