mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-27 18:11:57 +00:00
Try to prevent long queue lengths.
This commit is contained in:
parent
c7e5299bee
commit
7c1155392a
@ -45,6 +45,22 @@ MAKE_REFLECT_STRUCT(Out_Progress::Params,
|
|||||||
activeThreads);
|
activeThreads);
|
||||||
MAKE_REFLECT_STRUCT(Out_Progress, jsonrpc, method, params);
|
MAKE_REFLECT_STRUCT(Out_Progress, jsonrpc, method, params);
|
||||||
|
|
||||||
|
// Instead of processing messages forever, we only process upto
|
||||||
|
// |kIterationSize| messages of a type at one time. While the import time
|
||||||
|
// likely stays the same, this should reduce overall queue lengths which means
|
||||||
|
// the user gets a usable index faster.
|
||||||
|
struct IterationLoop {
|
||||||
|
const int kIterationSize = 100;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
bool Next() {
|
||||||
|
return count++ < kIterationSize;
|
||||||
|
}
|
||||||
|
void Reset() {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct IModificationTimestampFetcher {
|
struct IModificationTimestampFetcher {
|
||||||
virtual ~IModificationTimestampFetcher() = default;
|
virtual ~IModificationTimestampFetcher() = default;
|
||||||
virtual optional<int64_t> GetModificationTime(const std::string& path) = 0;
|
virtual optional<int64_t> GetModificationTime(const std::string& path) = 0;
|
||||||
@ -522,7 +538,8 @@ bool IndexMergeIndexUpdates() {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool did_merge = false;
|
bool did_merge = false;
|
||||||
while (true) {
|
IterationLoop loop;
|
||||||
|
while (loop.Next()) {
|
||||||
optional<Index_OnIndexed> to_join = queue->on_indexed.TryPopBack();
|
optional<Index_OnIndexed> to_join = queue->on_indexed.TryPopBack();
|
||||||
if (!to_join) {
|
if (!to_join) {
|
||||||
queue->on_indexed.PushFront(std::move(*root));
|
queue->on_indexed.PushFront(std::move(*root));
|
||||||
@ -599,7 +616,8 @@ void Indexer_Main(Config* config,
|
|||||||
// Build one index per-indexer, as building the index acquires a global lock.
|
// Build one index per-indexer, as building the index acquires a global lock.
|
||||||
auto indexer = IIndexer::MakeClangIndexer();
|
auto indexer = IIndexer::MakeClangIndexer();
|
||||||
|
|
||||||
while (true) {
|
IterationLoop loop;
|
||||||
|
while (loop.Next()) {
|
||||||
bool did_work = false;
|
bool did_work = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -726,6 +744,7 @@ void QueryDb_OnIndexed(QueueManager* queue,
|
|||||||
import_manager->DoneQueryDbImport(updated_file.value.path);
|
import_manager->DoneQueryDbImport(updated_file.value.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
bool QueryDb_ImportMain(Config* config,
|
bool QueryDb_ImportMain(Config* config,
|
||||||
@ -740,7 +759,8 @@ bool QueryDb_ImportMain(Config* config,
|
|||||||
|
|
||||||
bool did_work = false;
|
bool did_work = false;
|
||||||
|
|
||||||
while (true) {
|
IterationLoop loop;
|
||||||
|
while (loop.Next()) {
|
||||||
optional<Index_DoIdMap> request = queue->do_id_map.TryPopFront();
|
optional<Index_DoIdMap> request = queue->do_id_map.TryPopFront();
|
||||||
if (!request)
|
if (!request)
|
||||||
break;
|
break;
|
||||||
@ -748,7 +768,8 @@ bool QueryDb_ImportMain(Config* config,
|
|||||||
QueryDb_DoIdMap(queue, db, import_manager, &*request);
|
QueryDb_DoIdMap(queue, db, import_manager, &*request);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
loop.Reset();
|
||||||
|
while (loop.Next()) {
|
||||||
optional<Index_OnIndexed> response = queue->on_indexed.TryPopFront();
|
optional<Index_OnIndexed> response = queue->on_indexed.TryPopFront();
|
||||||
if (!response)
|
if (!response)
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user