[LifetimeSafety] Build time regression (mid-single-digit)
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Adding `-Wlifetime-safety` causes a 4.5% build performance hit (~1 sec on a sample builder) on the following file from Chrome V8: https://source.chromium.org/chromium/chromium/src/+/main:v8/src/compiler/turboshaft/csa-branch-elimination-phase.cc;drc=f2d33c2193fc819b5b92f284fc7f84b37db0ee87 (with extra lifetime annotations added to multiple headers).
Excerpt from `perf diff` between the profiles recorded via `perf record -g` for `-Wno-lifetime-safety` and `-Wlifetime-safety`:
```
# Event 'cycles:Pu'
#
# Baseline Delta Abs Shared Object Symbol
# ........ ......... .................... ...................................................................................................................................................................................................................................................................................................................................................................
#
+0.30% clang-23 [.] clang::lifetimes::internal::LoanPropagationAnalysis::LoanPropagationAnalysis(clang::CFG const&, clang::AnalysisDeclContext&, clang::lifetimes::internal::FactManager&, llvm::ImmutableMap, llvm::ImmutableSet, clang::lifetimes::internal::LivenessInfo, llvm::ImutKeyValueInfo, llvm::detail::DenseMapPair >::~DenseMap()
0.44% -0.12% clang-23 [.] clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl)
0.64% +0.12% libc.so.6 [.] cfree@GLIBC_2.2.5
0.49% -0.11% clang-23 [.] clang::RecordDecl::field_begin() const
0.56% -0.11% clang-23 [.] clang::TypeLoc::getFullDataSizeForType(clang::QualType)
+0.11% clang-23 [.] clang::lifetimes::internal::OriginManager::getOrCreateList(clang::Expr const*)
0.00% +0.11% clang-23 [.] clang::lifetimes::isGslPointerType(clang::QualType)
0.83% +0.10% libc.so.6 [.] malloc
+0.09% clang-23 [.] llvm::ImutAVLTree, llvm::ImmutableSet, llvm::ImutContainerInfo > > > >::destroy()
+0.09% clang-23 [.] clang::lifetimes::internal::FactsGenerator::run()
1.39% -0.09% clang-23 [.] clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo&, clang::DefaultArguments const&, bool, clang::Sema::CheckTemplateArgumentInfo&, bool, bool*)
3.12% -0.08% clang-23 [.] llvm::FoldingSetBase::FindNodeOrInsertPos(llvm::FoldingSetNodeID const&, void*&, llvm::FoldingSetBase::FoldingSetInfo const&)
+0.08% clang-23 [.] clang::StmtVisitorBase::Visit(clang::Stmt const*)
1.02% -0.08% clang-23 [.] clang::FunctionProtoType::Profile(llvm::FoldingSetNodeID&, clang::ASTContext const&)
0.27% -0.08% clang-23 [.] clang::TemplateArgument::Profile(llvm::FoldingSetNodeID&, clang::ASTContext const&) const
+0.08% clang-23 [.] clang::lifetimes::internal::runLifetimeChecker(clang::lifetimes::internal::LoanPropagationAnalysis const&, clang::lifetimes::internal::LiveOriginsAnalysis const&, clang::lifetimes::internal::FactManager const&, clang::AnalysisDeclContext&, clang::lifetimes::LifetimeSafetySemaHelper*)
+0.07% clang-23 [.] clang::lifetimes::internal::LoanPropagationAnalysis::Impl::AnalysisImpl(clang::CFG const&, clang::AnalysisDeclContext&, clang::lifetimes::internal::FactManager&, llvm::ImmutableMap, clang::lifetimes::internal::FactManager&::ImmutableSet, llvm::detail::DenseMapPair >, clang::CFGBlock const*, clang::lifetimes::internal::(anonymous namesp
1.10% +0.07% libc.so.6 [.] __memcmp_avx2_movbe
1.94% -0.06% clang-23 [.] llvm::FoldingSetBase::GrowBucketCount(unsigned int, llvm::FoldingSetBase::FoldingSetInfo const&)
0.21% -0.06% clang-23 [.] llvm::FoldingSetNodeID::operator==(llvm::FoldingSetNodeID const&) const
0.22% -0.06% clang-23 [.] (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType)
0.15% -0.06% clang-23 [.] clang::Sema::checkSpecializationReachability(clang::SourceLocation, clang::NamedDecl*)
0.28% -0.06% clang-23 [.] GetFullTypeForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*)
0.13% +0.06% clang-23 [.] clang::DeclContext::getRedeclContext()
+0.06% clang-23 [.] llvm::DenseMapBase, llvm::detail::DenseMapPair >, clang::CFGBlock const*, clang::lifetimes::internal::(anonymous namesp
0.14% +0.06% clang-23 [.] llvm::SmallVectorTemplateBase::grow(unsigned long)
0.17% +0.06% clang-23 [.] clang::FunctionDecl::getNumParams() const
0.09% -0.06% clang-23 [.] clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject*)
0.13% -0.05% clang-23 [.] clang::FunctionProtoType::FunctionProtoType(clang::QualType, llvm::ArrayRef, clang::QualType, clang::FunctionProtoType::ExtProtoInfo const&)
0.33% +0.05% clang-23 [.] clang::CXXBasePaths::lookupInBases(clang::ASTContext&, clang::CXXRecordDecl const*, llvm::function_ref, bool)
0.20% -0.05% clang-23 [.] clang::Sema::AddArgumentDependentLookupCandidates(clang::DeclarationName, clang::SourceLocation, llvm::ArrayRef, clang::TemplateArgumentListInfo*, clang::OverloadCandidateSet&, bool)
0.06% +0.05% libc.so.6 [.] _int_free_chunk
+0.05% clang-23 [.] bool llvm::DenseMapBase, llvm::detail::DenseMapPair >, clang::CFGBlock const*, clang::lifetimes::internal::(anonymous n
0.17% +0.05% clang-23 [.] clang::Decl::getAvailability(std::__cxx11::basic_string, std::allocator >*, llvm::VersionTuple, llvm::StringRef*) const
0.20% -0.05% clang-23 [.] clang::FunctionDecl::getBuiltinID(bool) const
0.09% +0.05% libc.so.6 [.] _int_free_create_chunk
0.12% -0.05% clang-23 [.] clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool)
0.07% +0.05% clang-23 [.] clang::NestedNameSpecifierLoc::getBeginLoc() const
0.15% -0.05% clang-23 [.] clang::Type::getContainedDeducedType() const
0.24% +0.05% clang-23 [.] clang::FunctionDecl::getCanonicalDecl()
0.16% -0.05% clang-23 [.] clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext)...
```
I won't attach the artifacts on the bug publicly, but some stats for the preprocessed file: 20MB, ~3'000 `[[clang::lifetimebound]]` annotations, ~50 `[[gsl::Owner]]`s, ~90 `[[gsl::Pointer]]`s.
Contributor guide
Assessment
This issue has not been assessed yet.