From e309712bd1c7b210187018003e8f3141c56bd8ce Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Mon, 2 Dec 2019 11:10:24 -0800 Subject: [PATCH] Default to using 80% of cores available (instead of 100%) for indexing --- src/config.cc | 9 +++++++++ src/config.hh | 6 +++++- src/messages/initialize.cc | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/config.cc b/src/config.cc index 659956b0..97cb80cf 100644 --- a/src/config.cc +++ b/src/config.cc @@ -3,6 +3,9 @@ #include "config.hh" +#include +#include + namespace ccls { Config *g_config; @@ -16,4 +19,10 @@ void doPathMapping(std::string &arg) { } } } + +int defaultIndexThreadCount() { + constexpr float kIndexThreadUtilization = 0.8; + return std::max(1, static_cast(std::thread::hardware_concurrency() * + kIndexThreadUtilization)); +} } // namespace ccls diff --git a/src/config.hh b/src/config.hh index 751a712c..6ab1ba9f 100644 --- a/src/config.hh +++ b/src/config.hh @@ -8,6 +8,10 @@ #include namespace ccls { + +// Select a reasonable default number of threads to use for indexing. +int defaultIndexThreadCount(); + /* The language client plugin needs to send initialization options in the `initialize` request to the ccls language server. @@ -286,7 +290,7 @@ struct Config { bool parametersInDeclarations = true; // Number of indexer threads. If 0, 80% of cores are used. - int threads = 0; + int threads = defaultIndexThreadCount(); // Whether to reparse a file if write times of its dependencies have // changed. The file will always be reparsed if its own write time changes. diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index b015d98d..691b56a0 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -374,6 +374,10 @@ void do_initialize(MessageHandler *m, InitializeParam ¶m, // Start indexer threads. Start this after loading the project, as that // may take a long time. Indexer threads will emit status/progress // reports. + // + // By default config.hh will select 80% of the available cores to use as + // index threads, but explicitly specifying threads=0 will instead use all + // available cores. if (g_config->index.threads == 0) g_config->index.threads = (int)std::thread::hardware_concurrency();