From 8f785a8d190032ac71b72a199f355c5fcba31019 Mon Sep 17 00:00:00 2001 From: lerman25 Date: Thu, 12 Nov 2026 16:37:12 +0200 Subject: [PATCH] Prefetch vectors and graph data during NaviX bridge traversal --- src/VecSim/algorithms/hnsw/hnsw_batch_iterator.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/VecSim/algorithms/hnsw/hnsw_batch_iterator.h b/src/VecSim/algorithms/hnsw/hnsw_batch_iterator.h index 034d2f38d..19d38b450 100644 --- a/src/VecSim/algorithms/hnsw/hnsw_batch_iterator.h +++ b/src/VecSim/algorithms/hnsw/hnsw_batch_iterator.h @@ -166,9 +166,15 @@ VecSimQueryReply_Code HNSW_BatchIterator::expandNavix(idType ++navix.stats->expandedNodes; ++navix.stats->bridgeExpansions; } - for (idType neighbor : navix_direct) { + for (size_t i = 0; i < navix_direct.size(); ++i) { + if (i + 1 < navix_direct.size()) { + const idType next = navix_direct[i + 1]; + __builtin_prefetch(visited_list->getElementsTags() + next); + __builtin_prefetch(index->getDataByInternalId(next)); + } if (VECSIM_TIMEOUT(this->getTimeoutCtx())) return VecSim_QueryReply_TimedOut; + const idType neighbor = navix_direct[i]; if (hasVisitedNode(neighbor)) continue; visitNode(neighbor); @@ -263,6 +269,8 @@ VecSimQueryReply_Code HNSW_BatchIterator::scanNavix( candidatesLabelsMaxHeap *top_candidates) { while (!candidates.empty()) { auto [distance, id] = candidates.top(); + __builtin_prefetch(index->getGraphDataByInternalId(id)); + __builtin_prefetch(index->getMetaDataAddress(id)); // Leave bound ties on the frontier for the next batch. if (distance >= this->lower_bound && top_candidates->size() >= this->ef) break;