[MOD-16696] Use one-byte HNSW node locks#983
Open
GuyAv46 wants to merge 2 commits into
Open
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #983 +/- ##
==========================================
- Coverage 97.12% 97.10% -0.03%
==========================================
Files 141 141
Lines 8164 8176 +12
==========================================
+ Hits 7929 7939 +10
- Misses 235 237 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dor-forer
reviewed
Jul 7, 2026
dor-forer
approved these changes
Jul 7, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 81dc0e6. Configure here.
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
Revives the old one-byte mutex idea on top of current
main, but keeps the graph-data layout natural by moving per-node HNSW locks into an index-owned lock vector.Changes:
vecsim_stl::one_byte_mutex, backed bystd::atomic<uint8_t>::wait/notify_one.std::mutex neighborsGuardfromElementGraphData.elementLocks, a per-internal-id lock vector owned byHNSWIndexand resized with index capacity.Expected memory effect:
ElementGraphDatano longer carries astd::mutexper vector.Validation
Local validation in a fresh worktree from
origin/main:make buildctest --output-on-failure -R 'test_allocator|test_hnsw|test_hnsw_parallel' -j$(nproc)./test_hnsw_parallel./test_allocator --gtest_filter='*hnsw*'ROOT=/home/guy/Code/VectorSimilarity-hnsw-one-byte-locks ./test_hnsw --gtest_brief=1Note:
make check-formatcurrently reports pre-existing unrelated formatting violations in files outside this change (for examplebatch_iterator.h, benchmark headers, and existing constructors intest_allocator.cpp). The files touched in this PR were formatted selectively.Benchmark request
Please run benchmark comparison for this PR. I am adding the
benchmarks-alllabel to trigger the benchmark workflow.Note
Medium Risk
Touches core HNSW concurrency on graph mutations and parallel search; correctness depends on the new lock primitive and id-indexed locking staying aligned with existing deadlock ordering.
Overview
HNSW neighbor-link locking moves out of packed graph nodes into an index-owned
elementLocksvector keyed by internal id, with a new compactvecsim_stl::one_byte_mutex(atomic wait/notify) instead ofstd::mutexon eachElementGraphData.lockNodeLinks/unlockNodeLinksnow take onlyidType; search, insert, delete/repair, batch iteration, and debug paths were updated accordingly.elementLocksis initialized on construct/load and grows withresizeIndexCommon. Memory estimation and allocator tests count one byte per capacity slot for the lock vector.Reviewed by Cursor Bugbot for commit e6da02b. Bugbot is set up for automated code reviews on this repo. Configure here.