From da8daa3fe8e84cd8c4664edc17ddb949f48b7f62 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Thu, 28 Dec 2017 13:10:15 +0000 Subject: [PATCH] [clangd] Skip function bodies when building the preamble Summary: To make building preambles faster and keep them smaller. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41495 llvm-svn: 321521 --- clang-tools-extra/clangd/ClangdUnit.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index 5fa8cd33a9b7..82ca109d2a53 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -529,12 +529,22 @@ CppFile::deferRebuild(StringRef NewContents, IntrusiveRefCntPtr PreambleDiagsEngine = CompilerInstance::createDiagnostics( &CI->getDiagnosticOpts(), &PreambleDiagnosticsConsumer, false); + + // Skip function bodies when building the preamble to speed up building + // the preamble and make it smaller. + assert(!CI->getFrontendOpts().SkipFunctionBodies); + CI->getFrontendOpts().SkipFunctionBodies = true; + CppFilePreambleCallbacks SerializedDeclsCollector; auto BuiltPreamble = PrecompiledPreamble::Build( *CI, ContentsBuffer.get(), Bounds, *PreambleDiagsEngine, VFS, PCHs, /*StoreInMemory=*/That->StorePreamblesInMemory, SerializedDeclsCollector); + // When building the AST for the main file, we do want the function + // bodies. + CI->getFrontendOpts().SkipFunctionBodies = false; + if (BuiltPreamble) { log(Ctx, "Built preamble of size " + Twine(BuiltPreamble->getSize()) + " for file " + Twine(That->FileName));