perf: speed up string_matcher hot path and fix index-list pruning#28
Open
Garulf wants to merge 1 commit into
Open
perf: speed up string_matcher hot path and fix index-list pruning#28Garulf wants to merge 1 commit into
Garulf wants to merge 1 commit into
Conversation
- Compare partial word matches with a C-level slice comparison instead of a per-char loop that never short-circuited - Compute acronym char/number flags once per character instead of up to twice each via nested helper calls; reorder is_acronym_char so the cheap positional checks run before isupper() - Bind the current character via enumerate and hoist len() calls out of the per-character loop; drop the dead second clause of the break condition - Inline the trivial all_query_substrings_matched_func wrapper - Use bisect for calculate_closest_space_index (space_indices is sorted) - Fix pop-while-iterating in get_updated_index_list that skipped elements, leaving stale highlight indices; now matches upstream RemoveAll semantics - Split the query with split() so consecutive spaces no longer produce empty substrings that raise IndexError Verified against a 335k-case corpus: scores and match results are identical; only the two fixed bugs change behavior. ~1.7x faster on a mixed workload.
Garulf
force-pushed
the
perf/string-matcher
branch
from
July 13, 2026 12:52
eb4eda6 to
0b8ee07
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Efficiency pass over
pyflowlauncher/string_matcher.pykeeping the algorithm's shape, plus two bug fixes found along the way. The matcher runs once per candidate result per keystroke, so per-character costs dominate.Speedups
all_previous_chars_matchednow uses a single slice comparison (C-level, short-circuiting) instead of a per-char Python loop that kept comparing after the first mismatchis_acronym+is_acronym_countre-evaluatedisupper()/isdigit()/prev-space up to twice each per character.is_acronym_charalso checks cheap positional conditions beforeisupper()enumerateand hoistslen()calls; removed the deadX or (X and Y)half of the break conditionall_query_substrings_matched_funcwrappercalculate_closest_space_indexusesbisect_left(space_indicesis built sorted)Bug fixes
get_updated_index_listpopped from the list while iterating it, skipping the element after each removal and leaving stale highlight indices. Now a comprehension, matching the upstream C#RemoveAll(x => x >= firstMatchedIndexInWord)semanticssplit(' ')and raisedIndexError;split()fixes thisVerification
IndexErrorcases now return no-match, 4 cases lose the stale highlight indices)tox -e lint,type,py38,py312all green (136 tests), with two new regression tests