Skip to content

Conversation

@hokein
Copy link
Collaborator

@hokein hokein commented Jul 15, 2025

The Declarator class is large (4584 bytes) and used as a stack-local variable during parsing.

This patch reduces the default size of its DeclTypeInfo member, reducing the overall size down to 3880 bytes. This allows clang handle more deeply nested expressions without exhausting the stack.

Combined with #148726, the nesting threshold for such expressions increases to ~1100.

No performance impact being observed.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)

Changes

The Declarator class is large (4584 bytes) and used as a stack-local variable during parsing.

This patch reduces the default size of its DeclTypeInfo member, reducing the overall size down to 3880 bytes. This allows clang handle more deeply nested expressions without exhausting the stack.

Combined with #148726, the nesting threshold for such expressions increases to ~1100.

No performance impact being observed.


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

1 Files Affected:

  • (modified) clang/include/clang/Sema/DeclSpec.h (+1-1)
diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index 567ad2d5934d4..4b7c8d609735f 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -1918,7 +1918,7 @@ class Declarator {
   /// parsed.  This is pushed from the identifier out, which means that element
   /// #0 will be the most closely bound to the identifier, and
   /// DeclTypeInfo.back() will be the least closely bound.
-  SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
+  SmallVector<DeclaratorChunk, 4> DeclTypeInfo;
 
   /// InvalidType - Set by Sema::GetTypeForDeclarator().
   LLVM_PREFERRED_TYPE(bool)

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! 8 declarator chunks is actually quite a bit, I suspect 4 is a more sensible default for the average TU. 2 might be a bit too few for what I'd suspect is the average use case.

@hokein hokein merged commit a2b3110 into llvm:main Jul 15, 2025
12 checks passed
hokein added a commit to hokein/llvm-project that referenced this pull request Jul 15, 2025
The `Declarator` class is large (4584 bytes) and used as a stack-local
variable during parsing.

This patch reduces the default size of its `DeclTypeInfo` member,
reducing the overall size down to 3880 bytes. This allows clang handle
more deeply nested expressions without exhausting the stack.

Combined with llvm#148726, the nesting threshold for such expressions
increases to `~1100`.

No performance impact being
[observed](https://llvm-compile-time-tracker.com/compare.php?from=d4f5ed6a23464cbe831820cb695aa1d39b11e4aa&to=66ba54b8a295cc2759387ef2a4a162de2ad4946e&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.

4 participants