Skip to content

⚡ Bolt: optimize terminal search fast-path#330

Open
Lucenx9 wants to merge 1 commit into
mainfrom
bolt-optimize-search-17651554363905782397
Open

⚡ Bolt: optimize terminal search fast-path#330
Lucenx9 wants to merge 1 commit into
mainfrom
bolt-optimize-search-17651554363905782397

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Jul 8, 2026

Copy link
Copy Markdown
Owner

💡 What:
The optimization modifies for_each_char_match_start in terminal_search.rs. Before spinning up iterators (.iter().zip()) for the rest of the string slice to test matching string queries, it checks if the first characters match with chars_eq_ignore_case().

🎯 Why:
zip() and .iter() involve heavy setups inside hot paths (a loop iterating thousands of lines of terminal output). In the extremely common scenario where the first character doesn't match the query, this setup is completely wasted CPU cycles and slows down the scrollback string search significantly.

📊 Impact:
Eliminates slice and zip allocation overhead for the vast majority of iteration steps during a terminal text search.

🔬 Measurement:
The improvement can be measured via the bench harness for this specific search loop which triggers heavily loaded simulated Terminal traces.


PR created automatically by Jules for task 17651554363905782397 started by @Lucenx9

This change speeds up terminal scrollback search by adding a first-character fast path in for_each_char_match_start, avoiding iterator/slice setup when the leading character already doesn’t match. GTK terminal search behavior stays the same, but common-case CPU work is reduced during large-output searches. No socket/core Rust API changes, tests, or security/privacy impacts were introduced.

Optimized `terminal_search`'s inner loop to quickly short-circuit on the first character difference. This avoids paying the `zip()` iterator and slice setup cost for the vast majority of non-matching offsets when checking terminal scrollback.

Co-authored-by: Lucenx9 <185146821+Lucenx9@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c62b4b08-ceff-43b4-b7a9-0ee3c1916f9c

📥 Commits

Reviewing files that changed from the base of the PR and between 891c9e7 and 769d39a.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs

📝 Walkthrough

Walkthrough

The change refactors for_each_char_match_start in terminal_search.rs to first compare a single character before checking the remaining needle tail against the haystack, replacing the previous full-substring zip comparison. A note file documents the observed slowdown and intended fix.

Changes

Search matching optimization

Layer / File(s) Summary
Fast-path first-character check
crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs, .jules/bolt.md
Match logic now compares haystack[index] to the needle's first character before zipping the remaining needle tail against the corresponding haystack slice, replacing the prior full-substring zip+all approach; a note documents the change rationale.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: frontend, rust, gtk

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change by describing the terminal search fast-path optimization.
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.
Privacy Boundary ✅ Passed Diff only changes in-memory terminal search matching and a note file; no telemetry, network, or persistence code was added.
Terminal Command Safety ✅ Passed Patch only changes terminal_search matching logic and a note file; it doesn't touch PTY/socket/shell/worktree/packaging or command execution.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-optimize-search-17651554363905782397

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.

@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: 769d39a96c

ℹ️ 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 .jules/bolt.md
@@ -0,0 +1,3 @@
## 2025-02-15 - Fast text search

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove bot metadata from the repo root

This adds a new top-level .jules/ directory for transient agent notes, but AGENTS.md says to “Prefer adding a new top-level directory only for a durable category of repo content.” Keeping this file commits bot-local state that is not a product, docs, release, or source-of-truth artifact, so the repository shape drifts from the documented contract; please drop it or move any durable guidance into an existing maintained file.

Useful? React with 👍 / 👎.

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