@@ -370,7 +370,7 @@ class TieredSVSIndex : public VecSimTieredIndex<DataType, float> {
370
370
// calculating all the distances and access the BF index. We take the lock on this
371
371
// call.
372
372
auto cur_flat_results = [this , n_res]() {
373
- std::shared_lock<std::shared_mutex> flat_lock{index->flatIndexGuard };
373
+ std::shared_lock flat_lock{index->flatIndexGuard };
374
374
return flat_iterator->getNextResults (n_res, BY_SCORE_THEN_ID);
375
375
}();
376
376
// This is also the only time `getNextResults` on the BF iterator can fail.
@@ -537,20 +537,20 @@ class TieredSVSIndex : public VecSimTieredIndex<DataType, float> {
537
537
std::vector<DataType> vectors_to_move;
538
538
539
539
{ // lock frontendIndex from modifications
540
- std::shared_lock<std::shared_mutex> frontend_lock {this ->flatIndexGuard };
540
+ std::shared_lock flat_lock {this ->flatIndexGuard };
541
541
542
542
auto flat_index = this ->GetFlatIndex ();
543
- auto frontend_index_size = this ->frontendIndex ->indexSize ();
543
+ const auto frontend_index_size = this ->frontendIndex ->indexSize ();
544
544
const size_t dim = flat_index->getDim ();
545
545
labels_to_move.reserve (frontend_index_size);
546
546
vectors_to_move.reserve (frontend_index_size * dim);
547
547
548
- for (idType i = 0 ; i < frontend_index_size; ++i ) {
548
+ for (idType i = 0 ; i < frontend_index_size; i++ ) {
549
549
labels_to_move.push_back (flat_index->getVectorLabel (i));
550
550
auto data = flat_index->getDataByInternalId (i);
551
551
vectors_to_move.insert (vectors_to_move.end (), data, data + dim);
552
552
}
553
- // restart journal from current frontend index state
553
+ // reset journal to the current frontend index state
554
554
swaps_journal.clear ();
555
555
} // release frontend index
556
556
@@ -589,6 +589,8 @@ class TieredSVSIndex : public VecSimTieredIndex<DataType, float> {
589
589
}
590
590
}
591
591
// delete vectors from the frontend index in reverse order
592
+ // it increases the chance of avoiding swaps in the frontend index and performance
593
+ // improvement
592
594
size_t deleted = 0 ;
593
595
for (idType i = labels_to_move.size (); i > 0 ; --i) {
594
596
auto label = labels_to_move[i - 1 ];
@@ -678,13 +680,13 @@ class TieredSVSIndex : public VecSimTieredIndex<DataType, float> {
678
680
// Async mode - add vector to the frontend index and schedule an update job if needed.
679
681
if (!this ->backendIndex ->isMultiValue ()) {
680
682
// Remove vector from the backend index if it exists in case of non-MULTI.
681
- std::scoped_lock lock (this ->mainIndexGuard );
683
+ std::lock_guard lock (this ->mainIndexGuard );
682
684
ret -= svs_index->deleteVectors (&label, 1 );
683
685
// If main index is empty then update_threshold is trainingTriggerThreshold,
684
686
// overwise it is 1.
685
687
}
686
688
{
687
- std::shared_lock<std::shared_mutex> lock (this ->mainIndexGuard );
689
+ std::shared_lock lock (this ->mainIndexGuard );
688
690
update_threshold = this ->backendIndex ->indexSize () == 0 ? this ->trainingTriggerThreshold
689
691
: this ->updateTriggerThreshold ;
690
692
}
@@ -875,7 +877,7 @@ class TieredSVSIndex : public VecSimTieredIndex<DataType, float> {
875
877
void runGC () override {
876
878
TIERED_LOG (VecSimCommonStrings::LOG_VERBOSE_STRING,
877
879
" running asynchronous GC for tiered SVS index" );
878
- std::unique_lock<std::shared_mutex> backend_lock {this ->mainIndexGuard };
880
+ std::lock_guard lock {this ->mainIndexGuard };
879
881
// VecSimIndexAbstract::runGC() is protected
880
882
static_cast <VecSimIndexInterface *>(this ->backendIndex )->runGC ();
881
883
}
0 commit comments