perf(search): 検索の大文字小文字無視マッチに ASCII 高速パスを追加#440
Merged
Conversation
issue / memory 検索は入力1キーごとに再実行され、その都度すべての候補 フィールド(title / body)を `to_lowercase()` で畳み込んでいた。本文は 数 KB に及ぶことがあり、毎キーストロークで全件ぶんの新規 String 確保 + Unicode 変換が走るのが本レイヤで最も繰り返されるコストだった。 `matches_folded` の畳み込みを `contains_folded` に切り出し、フィールドと needle の双方が ASCII のときはバイト単位の大文字小文字無視走査(その場で スキャン、確保なし)を行う高速パスを追加。いずれかが非 ASCII の場合は従来 どおり `to_lowercase().contains()` にフォールバックし、マルチバイトの needle が文字境界をまたいで誤マッチしない性質を維持する。 挙動は不変。ASCII 高速パス(needle がフィールドより長い場合を含む)と 非 ASCII フォールバックの両経路を網羅するテストを追加。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📊 Test Coverage
🎉✨ パーフェクト!全ファイル Lines カバレッジ 100% を達成しました 🏆🐰 |
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.
目的
issue / memory のインクリメンタル検索のホットパスを軽くする。検索は入力1キーごとに再実行され、その都度すべての候補フィールド(title / body)を畳み込んでいたため、本レイヤで最も繰り返される文字列コストになっていた。
背景(性能レビューでの指摘)
matches_foldedは候補フィールドごとにf.to_lowercase().contains(needle)を実行する。to_lowercase()は本文(数 KB に及びうる)の新規 String 確保 + Unicode 変換を伴い、N 件 × 毎キーストロークでO(全本文バイト数)を支払っていた。変更内容
contains_folded(field, needle)に切り出した。windows+eq_ignore_ascii_case)で判定する。needleはfold_queryで既に小文字化済み。to_lowercase().contains()。マルチバイト needle が文字境界をまたいで誤マッチしない性質(モジュールドキュメント参照)を維持する。挙動は不変。
テスト・確認方法
cargo fmt/cargo clippy --all-targets -- -D warningsクリーン。cargo test全 2253 件 pass。ASCII 高速パス(needle がフィールドより長いケースを含む)と非 ASCII フォールバック(一致・不一致の両方)を網羅するテストを追加。