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