Index: clangd/TUScheduler.cpp =================================================================== --- clangd/TUScheduler.cpp +++ clangd/TUScheduler.cpp @@ -383,6 +383,14 @@ // Remove the old AST if it's still in cache. IdleASTs.take(this); + if (WantDiags == WantDiagnostics::No) { + // If no diagnostics were requested, building it in advance might be a + // waste if it will be removed from the cache before it is first accessed. + // So we choose to avoid building it in the first place, the rebuild will + // happen on first access instead. + return; + } + // Build the AST for diagnostics. llvm::Optional AST = buildAST(FileName, std::move(Invocation), Inputs, NewPreamble, PCHs);