Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ security_best_practices_report.md
# ForkTTY runtime
/tmp/forktty.sock
.worktrees/
/zig-linux-x86_64-0.14.0
/zig-linux-x86_64-0.14.0.tar.xz
/zig-linux-x86_64-0.13.0
/zig-linux-x86_64-0.13.0.tar.xz
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2026-08-14 - Fast-Path ASCII checks in Terminal 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.

P1 Badge Record the terminal-search speedup in the changelog

This user-visible reduction in search latency is recorded only in the Jules note, so release notes built from this commit will omit the improvement. Add an entry under CHANGELOG.md's ## [Unreleased] section as required for every user-visible change.

AGENTS.md reference: AGENTS.md:L183-L183

Useful? React with πŸ‘Β / πŸ‘Ž.

**Learning:** Hoisting the computation of ASCII lowercase and uppercase values for the needle's first character outside the hot search loop and doing inline ASCII equality checks `h == first_lower || h == first_upper` eliminates function call overhead (`chars_eq_ignore_case`) for the vast majority of non-matching characters during massive terminal scrollback searches.
**Action:** Always consider manually hoisting lightweight checks (like ASCII case bounds) out of hot iterator loops in Rust when dealing with millions of character iterations.
13 changes: 12 additions & 1 deletion crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,22 @@ fn for_each_char_match_start(
return;
}
let first_needle = needle[0];
let first_is_ascii = first_needle.is_ascii();
let first_lower = first_needle.to_ascii_lowercase();
let first_upper = first_needle.to_ascii_uppercase();

let mut index = 0;
while index + needle.len() <= haystack.len() {
// Fast-path: short-circuit the full substring check if the first character
// doesn't match, avoiding iterator overhead in the common case.
if !chars_eq_ignore_case(haystack[index], first_needle) {
let h = haystack[index];
let first_match = if first_is_ascii && h.is_ascii() {
h == first_lower || h == first_upper
} else {
chars_eq_ignore_case(h, first_needle)
};

if !first_match {
index += 1;
continue;
}
Expand Down
Loading