Skip to content

Commit 81a6700

Browse files
authored
Merge pull request #19 from akyrtzi/global-unit-queue-batches
[Index] For registering units process them in batches of maximum 10 at a time
2 parents 0af484d + 76623ca commit 81a6700

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/Index/IndexDatastore.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ sys::TimePoint<> UnitMonitor::getModTimeForOutOfDateCheck(StringRef filePath) {
693693
// IndexDatastoreImpl
694694
//===----------------------------------------------------------------------===//
695695

696+
static const unsigned MAX_STORE_EVENTS_TO_PROCESS_PER_WORK_UNIT = 10;
697+
696698
namespace {
697699
/// A thread-safe deque object for UnitEventInfo objects.
698700
class UnitEventInfoDeque {
@@ -705,13 +707,17 @@ class UnitEventInfoDeque {
705707
EventsDequeue.insert(EventsDequeue.end(), evts.begin(), evts.end());
706708
}
707709

708-
Optional<UnitEventInfo> popFront() {
710+
std::vector<UnitEventInfo> popFront(unsigned N) {
709711
sys::ScopedLock L(StateMtx);
710-
if (EventsDequeue.empty())
711-
return None;
712-
UnitEventInfo evt = EventsDequeue.front();
713-
EventsDequeue.pop_front();
714-
return evt;
712+
std::vector<UnitEventInfo> evts;
713+
for (unsigned i = 0; i < N; ++i) {
714+
if (EventsDequeue.empty())
715+
break;
716+
UnitEventInfo evt = EventsDequeue.front();
717+
EventsDequeue.pop_front();
718+
evts.push_back(std::move(evt));
719+
}
720+
return evts;
715721
}
716722
};
717723
}
@@ -723,15 +729,14 @@ static void processUnitEventsIncrementally(std::shared_ptr<UnitEventInfoDeque> e
723729
std::weak_ptr<StoreUnitRepo> weakUnitRepo,
724730
std::shared_ptr<IndexSystemDelegate> delegate,
725731
dispatch_queue_t queue) {
726-
Optional<UnitEventInfo> evtOpt = evts->popFront();
727-
if (!evtOpt.hasValue())
732+
std::vector<UnitEventInfo> poppedEvts = evts->popFront(MAX_STORE_EVENTS_TO_PROCESS_PER_WORK_UNIT);
733+
if (poppedEvts.empty())
728734
return;
729735
auto UnitRepo = weakUnitRepo.lock();
730736
if (!UnitRepo)
731737
return;
732738

733-
UnitEventInfo evt = evtOpt.getValue();
734-
UnitRepo->onFilesChange({evt}, [&](unsigned NumCompleted){
739+
UnitRepo->onFilesChange(poppedEvts, [&](unsigned NumCompleted){
735740
delegate->processingCompleted(NumCompleted);
736741
}, [&](){
737742
// FIXME: the database should recover.

0 commit comments

Comments
 (0)