Repository navigation
fix: release Python GIL and isolate concurrent index searches - #137
Merged
Merged
Conversation
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
Python index calls hold the GIL during native work, while HNSW and SymphonyQG searches update shared search-window state. Release the GIL around native index search, construction, updates, and file I/O, and keep search parameters local to each call so independent Python threads can safely search an unchanged index.
Add per-index access guards: searches, saves, and property reads may coexist; conflicting mutations immediately raise
RuntimeError("Index is busy: conflicting operation in progress"). Retain input array owners and reacquire the GIL before Python object handling and guard destruction. AddQuantizedGraph::search_batch_with_efwhile preserving existing default-window APIs.Python signatures/defaults and saved-index formats remain unchanged. Downstream callers must synchronize conflicting updates and must not mutate input arrays during calls. C++ callers still synchronize mutations themselves; dependent C++ binaries should be rebuilt with matching headers/library. Document the concurrency contract and add Python/C++ regression tests. No release is included.
Testing
Reviewed and tested
46160f1againstmain(0973bef) on Linux x86-64, GCC 14.3, Python 3.13:RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF, GoogleTest 1.14.0): 320 passed, 1 conditional skip; independentOpenMPBindingpassed. Available generic, AVX2, and AVX-512 HNSW backend checks passed.git diff --check: passed.Windows, macOS, native ARM64, and ThreadSanitizer were not run locally.