From 16dc2971a67d7406a260188701f0345b54324478 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Thu, 20 Apr 2017 22:16:52 -0700 Subject: [PATCH] Automatically compute a good value for number of indexer threads to start. --- src/command_line.cc | 7 +++++-- src/language_server_api.h | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/command_line.cc b/src/command_line.cc index e38c52f1..a9d245f0 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -1673,8 +1673,11 @@ void QueryDbMain(IndexerConfig* config) { FileConsumer::SharedState file_consumer_shared; // Start indexer threads. - std::cerr << "[querydb] Starting " << config->indexerCount << " indexers" << std::endl; - for (int i = 0; i < config->indexerCount; ++i) { + int indexerCount = std::min(std::thread::hardware_concurrency(), 2) - 1; + if (config->indexerCount > 0) + indexerCount = config->indexerCount; + std::cerr << "[querydb] Starting " << indexerCount << " indexers" << std::endl; + for (int i = 0; i < indexerCount; ++i) { new std::thread([&]() { IndexMain(config, &file_consumer_shared, &project, &queue_do_index, &queue_do_id_map, &queue_on_id_mapped, &queue_on_indexed); }); diff --git a/src/language_server_api.h b/src/language_server_api.h index d204c102..7e63cd99 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -59,9 +59,14 @@ struct IndexerConfig { std::string cacheDirectory; NonElidedVector whitelist; NonElidedVector blacklist; - int indexerCount = 1; - int maxWorkspaceSearchResults = 1000; std::vector extraClangArguments; + + // Maximum workspace search results. + int maxWorkspaceSearchResults = 1000; + + // Force a certain number of indexer threads. If less than 1 a default value + // should be used. + int indexerCount = 0; // If false, the indexer will be disabled. bool enableIndexing = true; // If false, indexed files will not be written to disk. @@ -72,9 +77,10 @@ struct IndexerConfig { MAKE_REFLECT_STRUCT(IndexerConfig, cacheDirectory, whitelist, blacklist, - indexerCount, - maxWorkspaceSearchResults, extraClangArguments, + + maxWorkspaceSearchResults, + indexerCount, enableIndexing, enableCacheWrite, enableCacheRead);