Skip to content

Conversation

@hokein
Copy link
Collaborator

@hokein hokein commented Jun 5, 2025

This gives us another ~1.85% improvement (1617->1647 for the instantiation-depth-default.cpp) on clang's template instantiation depths,

No performance regressions have been observed: https://llvm-compile-time-tracker.com/compare.php?from=702e228249906d43687952d9a2f3d2f90d8024c6&to=61be4bfea92d52cfc3e48a3cabb1bc80cbebb7fa&stat=instructions:u

@hokein hokein requested a review from AaronBallman June 5, 2025 14:48
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 5, 2025

@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)

Changes

This gives us another ~1.85% improvement (1617->1647 for the instantiation-depth-default.cpp) on clang's template instantiation depths,

No performance regressions have been observed: https://llvm-compile-time-tracker.com/compare.php?from=702e228249906d43687952d9a2f3d2f90d8024c6&to=61be4bfea92d52cfc3e48a3cabb1bc80cbebb7fa&stat=instructions:u


Full diff: https://github.com/llvm/llvm-project/pull/142983.diff

2 Files Affected:

  • (modified) clang/include/clang/Sema/Template.h (+2-2)
  • (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1-1)
diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h
index af0c1e8506cf3..0c68ad9b9d90a 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -587,7 +587,7 @@ enum class TemplateSubstitutionKind : char {
     /// specializations that will need to be instantiated after the
     /// enclosing class's instantiation is complete.
     SmallVector<std::pair<ClassTemplateDecl *,
-                                ClassTemplatePartialSpecializationDecl *>, 4>
+                                ClassTemplatePartialSpecializationDecl *>, 1>
       OutOfLinePartialSpecs;
 
     /// A list of out-of-line variable template partial
@@ -595,7 +595,7 @@ enum class TemplateSubstitutionKind : char {
     /// enclosing variable's instantiation is complete.
     /// FIXME: Verify that this is needed.
     SmallVector<
-        std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
+        std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 1>
     OutOfLineVarPartialSpecs;
 
   public:
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index bcad815e1587f..7da09b149446a 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2394,7 +2394,7 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) {
     // Queue up any out-of-line partial specializations of this member
     // variable template; the client will force their instantiation once
     // the enclosing class has been instantiated.
-    SmallVector<VarTemplatePartialSpecializationDecl *, 4> PartialSpecs;
+    SmallVector<VarTemplatePartialSpecializationDecl *, 1> PartialSpecs;
     D->getPartialSpecializations(PartialSpecs);
     for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I)
       if (PartialSpecs[I]->getFirstDecl()->isOutOfLine())

@github-actions
Copy link

github-actions bot commented Jun 5, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@hokein hokein merged commit b6364ab into llvm:main Jun 6, 2025
7 checks passed
@hokein hokein deleted the perf/reduce-template-instantiation-size branch June 6, 2025 14:25
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
This gives us another ~1.85% improvement (1617->1647 for the
`instantiation-depth-default.cpp`) on clang's template instantiation
depths,

No performance regressions have been observed:
https://llvm-compile-time-tracker.com/compare.php?from=702e228249906d43687952d9a2f3d2f90d8024c6&to=61be4bfea92d52cfc3e48a3cabb1bc80cbebb7fa&stat=instructions:u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants