Skip to content

Conversation

ilya-biryukov
Copy link
Contributor

At some point the call to static TypedefType::Profile inside ASTContext::getTypedefType got out-of-sync with the non-static TypedefType::Profile.

This seem to cause some bad performance patterns with FoldingSet and are seeing 10x increases in compile times in certain scenarios. After this commit, the compile times go back to normal.

This commit does not include tests or benchmarks because we want to land this ASAP to unbreak our deployment. I will work on adding asserts, tests or benchmarks in a follow-up.

…ypedefType

At some point the call to static `TypedefType::Profile` inside
`ASTContext::getTypedefType` got out-of-sync with the non-static
`TypedefType::Profile`.

This seem to cause some bad performance patterns with `FoldingSet`
and are seeing 10x increases in compile times in certain scenarios.
After this commit, the compile times go back to normal.

This commit does not include tests or benchmarks because we want to land
this ASAP to unbreak our deployment. I will work on adding asserts,
tests or benchmarks in a follow-up.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2025

@llvm/pr-subscribers-clang

Author: Ilya Biryukov (ilya-biryukov)

Changes

At some point the call to static TypedefType::Profile inside ASTContext::getTypedefType got out-of-sync with the non-static TypedefType::Profile.

This seem to cause some bad performance patterns with FoldingSet and are seeing 10x increases in compile times in certain scenarios. After this commit, the compile times go back to normal.

This commit does not include tests or benchmarks because we want to land this ASAP to unbreak our deployment. I will work on adding asserts, tests or benchmarks in a follow-up.


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

1 Files Affected:

  • (modified) clang/lib/AST/ASTContext.cpp (+2-1)
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index dca05b41aee77..c04de4e132739 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5316,7 +5316,8 @@ ASTContext::getTypedefType(ElaboratedTypeKeyword Keyword,
   }
 
   llvm::FoldingSetNodeID ID;
-  TypedefType::Profile(ID, Keyword, Qualifier, Decl, UnderlyingType);
+  TypedefType::Profile(ID, Keyword, Qualifier, Decl,
+                       *TypeMatchesDeclOrNone ? QualType() : UnderlyingType);
 
   void *InsertPos = nullptr;
   if (FoldingSetPlaceholder<TypedefType> *Placeholder =

@ilya-biryukov
Copy link
Contributor Author

cc @mizvekov as I believe this is probably related to the new representation of NameQualifier.

Copy link
Contributor

@alexfh alexfh left a comment

Choose a reason for hiding this comment

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

Thank you for the fix!

Copy link
Member

@kadircet kadircet left a comment

Choose a reason for hiding this comment

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

ugh this looks quite fragile (not your fix but rather having multiple ways to call profile), i am worried we might have divergences in other places as well :(

i think it would be nice to handle that in a more principled way for the future. thanks for the fix!

@alexfh alexfh merged commit a69a406 into llvm:main Sep 9, 2025
12 checks passed
@ilya-biryukov
Copy link
Contributor Author

ugh this looks quite fragile (not your fix but rather having multiple ways to call profile), i am worried we might have divergences in other places as well :(

i think it would be nice to handle that in a more principled way for the future. thanks for the fix!

I am definitely worried as well and was trying to figure out a generic way to assert the two FoldingSetNodeIDs are the same. I didn't find one, but we could at least assert the IDs of the node after we create each type is the same as the one we looked up in the FoldingSet before we added it.

I'll prepare a PR to propose that so we can discuss this further.

@ilya-biryukov
Copy link
Contributor Author

ilya-biryukov commented Sep 9, 2025

Sent out a draft PR with an assert that seems to catch more cases like this: #157692, let's discuss further there.

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.

5 participants