fix(state): release lock between context queries in search_messages#3035
Closed
Kewe63 wants to merge 1 commit into
Closed
fix(state): release lock between context queries in search_messages#3035Kewe63 wants to merge 1 commit into
Kewe63 wants to merge 1 commit into
Conversation
The context-window queries (one per FTS5 match) were running inside the same lock acquisition as the primary FTS5 query, holding the lock for O(N) sequential SQLite round-trips. Move per-match context fetches outside the outer lock block so each acquires the lock independently, keeping critical sections short and allowing other threads to interleave.
1d10b79 to
58a17fc
Compare
Contributor
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.
The per-match context-window queries in
search_messages()(one SQLiteround-trip per FTS5 result) were running inside the same outer
with self._lock:block as the primary FTS5 query, holding the lockfor O(N) sequential I/O. This blocked all other threads (message writes,
session updates) for the entire duration of a search with many results.
Moved the per-match context fetches outside the outer lock so each
query acquires the lock independently, keeping critical sections short
and allowing other threads to interleave.
Test plan
search_messageswith multiple results and verify context rows are correct