Repository navigation
β‘ Bolt: Optimize terminal scrollback search with ASCII fast-path #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import sys | ||
|
|
||
| with open("crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs", "r") as f: | ||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is an unused implementation artifact: a repository-wide search finds no caller, and running it only performs an unchecked textual rewrite of AGENTS.md reference: AGENTS.md:L122-L124 Useful? React with πΒ / π. |
||
| text = f.read() | ||
|
|
||
| search = """ | ||
| let first_needle = needle[0]; | ||
| 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. | ||
| let h = haystack[index]; | ||
| if h.is_ascii() && h != first_lower && h != first_upper { | ||
| index += 1; | ||
| continue; | ||
| } | ||
| """ | ||
|
|
||
| replace = r""" | ||
| let first_needle = needle[0]; | ||
| let first_lower = first_needle.to_ascii_lowercase(); | ||
| let first_upper = first_needle.to_ascii_uppercase(); | ||
| // Only enable the ASCII fast-path if the needle itself is ASCII. | ||
| // If the needle is non-ASCII (e.g. Kelvin sign \u{212A}), it might still case-fold | ||
| // to an ASCII character, so we must fall back to full Unicode matching. | ||
| let can_fast_path = first_needle.is_ascii(); | ||
| 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. | ||
| let h = haystack[index]; | ||
| if can_fast_path && h.is_ascii() && h != first_lower && h != first_upper { | ||
| index += 1; | ||
| continue; | ||
| } | ||
| """ | ||
|
|
||
| text = text.replace(search.strip(), replace.strip()) | ||
|
|
||
| with open("crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs", "w") as f: | ||
| f.write(text) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit presents a measurable user-visible speedup for searches over large scrollback buffers, but
CHANGELOG.mdstill has an emptyUnreleasedsection, so the improvement will be absent from the next release notes. Add an Unreleased entry describing the optimized terminal search behavior.AGENTS.md reference: AGENTS.md:L183-L183
Useful? React with πΒ / π.