summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2019-08-12 13:40:27 +0000
committerHans Wennborg <hans@hanshq.net>2019-08-12 13:40:27 +0000
commit4c5d5233ebfac958dc799b61f90f5aa52e2a6bba (patch)
tree19e5878ab1a77b26fe7940f08df11168b0b7010a
parent02b5498b789a75fdad91fab584a362bf40a9603a (diff)
Merging r368498:
------------------------------------------------------------------------ r368498 | sammccall | 2019-08-10 01:03:32 +0200 (Sat, 10 Aug 2019) | 25 lines clangd: use -j for background index pool Summary: clangd supports a -j option to limit the amount of threads to use for parsing TUs. However, when using -background-index (the default in later versions of clangd), the parallelism used by clangd defaults to the hardware_parallelisn, i.e. number of physical cores. On shared hardware environments, with large projects, this can significantly affect performance with no way to tune it down. This change makes the -j parameter apply equally to parsing and background index. It's not perfect, because the total number of threads is 2x the -j value, which may still be unexpected. But at least this change allows users to prevent clangd using all CPU cores. Reviewers: kadircet, sammccall Reviewed By: sammccall Subscribers: javed.absar, jfb, sammccall, ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66031 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/branches/release_90@368569 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clangd/ClangdServer.cpp8
-rw-r--r--clangd/TUScheduler.cpp9
-rw-r--r--clangd/tool/ClangdMain.cpp6
3 files changed, 14 insertions, 9 deletions
diff --git a/clangd/ClangdServer.cpp b/clangd/ClangdServer.cpp
index 7e77e187..8cb72696 100644
--- a/clangd/ClangdServer.cpp
+++ b/clangd/ClangdServer.cpp
@@ -38,9 +38,11 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
+#include <algorithm>
#include <future>
#include <memory>
#include <mutex>
+#include <type_traits>
namespace clang {
namespace clangd {
@@ -101,8 +103,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
: nullptr),
GetClangTidyOptions(Opts.GetClangTidyOptions),
SuggestMissingIncludes(Opts.SuggestMissingIncludes),
- TweakFilter(Opts.TweakFilter),
- WorkspaceRoot(Opts.WorkspaceRoot),
+ TweakFilter(Opts.TweakFilter), WorkspaceRoot(Opts.WorkspaceRoot),
// Pass a callback into `WorkScheduler` to extract symbols from a newly
// parsed file and rebuild the file index synchronously each time an AST
// is parsed.
@@ -128,7 +129,8 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
BackgroundIdx = llvm::make_unique<BackgroundIndex>(
Context::current().clone(), FSProvider, CDB,
BackgroundIndexStorage::createDiskBackedStorageFactory(
- [&CDB](llvm::StringRef File) { return CDB.getProjectInfo(File); }));
+ [&CDB](llvm::StringRef File) { return CDB.getProjectInfo(File); }),
+ std::max(Opts.AsyncThreadsCount, 1u));
AddIndex(BackgroundIdx.get());
}
if (DynamicIdx)
diff --git a/clangd/TUScheduler.cpp b/clangd/TUScheduler.cpp
index a77d2269..573c8314 100644
--- a/clangd/TUScheduler.cpp
+++ b/clangd/TUScheduler.cpp
@@ -54,6 +54,7 @@
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/Threading.h"
#include <algorithm>
#include <memory>
#include <queue>
@@ -799,10 +800,10 @@ std::string renderTUAction(const TUAction &Action) {
} // namespace
unsigned getDefaultAsyncThreadsCount() {
- unsigned HardwareConcurrency = std::thread::hardware_concurrency();
- // C++ standard says that hardware_concurrency()
- // may return 0, fallback to 1 worker thread in
- // that case.
+ unsigned HardwareConcurrency = llvm::heavyweight_hardware_concurrency();
+ // heavyweight_hardware_concurrency may fall back to hardware_concurrency.
+ // C++ standard says that hardware_concurrency() may return 0; fallback to 1
+ // worker thread in that case.
if (HardwareConcurrency == 0)
return 1;
return HardwareConcurrency;
diff --git a/clangd/tool/ClangdMain.cpp b/clangd/tool/ClangdMain.cpp
index 840f3d64..c047a953 100644
--- a/clangd/tool/ClangdMain.cpp
+++ b/clangd/tool/ClangdMain.cpp
@@ -267,7 +267,8 @@ list<std::string> TweakList{
opt<unsigned> WorkerThreadsCount{
"j",
cat(Misc),
- desc("Number of async workers used by clangd"),
+ desc("Number of async workers used by clangd. Background index also "
+ "uses this many workers."),
init(getDefaultAsyncThreadsCount()),
};
@@ -308,7 +309,8 @@ opt<PCHStorageFlag> PCHStorage{
opt<bool> Sync{
"sync",
cat(Misc),
- desc("Parse on main thread. If set, -j is ignored"),
+ desc("Handle client requests on main thread. Background index still uses "
+ "its own thread."),
init(false),
Hidden,
};