-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[llvm-project] Backport upstream version of lazy template loading #17722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6c26e5f
to
72afea0
Compare
Test Results 19 files 19 suites 5d 6h 15m 50s ⏱️ For more details on these failures, see this check. Results for commit deb3e7a. ♻️ This comment has been updated with latest results. |
Results of This PR:
Master:
Without upstream/downstream patch:
|
That’s a bummer, we screwed up something badly upstream… |
@ChuanqiXu9, do you see something obvious that went wrong here? In our current workflows we deserialize 100Mb more with our upstream patch... |
Repeating the test of #14495 (comment) with |
6ab17c5
to
de0d97c
Compare
Hi @ChuanqiXu9 @vgvassilev, I had another look at the patch and found four places where things seem wrong. At least two of them are needed for ROOT, and with the last commit I pushed to this PR memory usage returns to the same level as
diff --git a/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp b/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp
index fb62454643..52c3e5ed1d 100644
--- a/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp
+++ b/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp
@@ -196,6 +196,21 @@ void TemplateArgumentHasher::AddDecl(const Decl *D) {
}
AddDeclarationName(ND->getDeclName());
+
+ // If this was a specialization we should take into account its template
+ // arguments. This helps to reduce collisions coming when visiting template
+ // specialization types (eg. when processing type template arguments).
+ ArrayRef<TemplateArgument> Args;
+ if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
+ Args = CTSD->getTemplateArgs().asArray();
+ else if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
+ Args = VTSD->getTemplateArgs().asArray();
+ else if (auto *FD = dyn_cast<FunctionDecl>(D))
+ if (FD->getTemplateSpecializationArgs())
+ Args = FD->getTemplateSpecializationArgs()->asArray();
+
+ for (auto &TA : Args)
+ AddTemplateArgument(TA);
}
void TemplateArgumentHasher::AddQualType(QualType T) {
diff --git a/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp b/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp
index 3d325774ba..d65f329ae8 100644
--- a/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp
+++ b/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp
@@ -7723,14 +7723,8 @@ void ASTReader::CompleteRedeclChain(const Decl *D) {
}
}
- if (Template) {
- // For partitial specialization, load all the specializations for safety.
- if (isa<ClassTemplatePartialSpecializationDecl,
- VarTemplatePartialSpecializationDecl>(D))
- Template->loadLazySpecializationsImpl();
- else
- Template->loadLazySpecializationsImpl(Args);
- }
+ if (Template)
+ Template->loadLazySpecializationsImpl(Args);
}
CXXCtorInitializer ** basically reverting what was done as part of the original D41416. Do you remember why that change was done during the upstream review process?
I pushed my (suspected) solutions for the first two points to this PR, and all ROOT tests seem to pass. I can submit patches for any of the above points upstream if you want, in the way that is most convenient (with a single PR, maybe that's easier to test?). We should only note that the changes cannot be backported for LLVM 20 because the hashing changes cause existing on-disk modules to break. |
@hahnjo, great job. That part was not clear to me either but since the patch departed quite far from the original state I decided I must be missing something. If we get to the same levels of memory and runtime consumption I can propose the next two steps:
|
Ok, but with which changes? The PR currently has 1&2, but I think we need to get agreement on which modifications we actually want. And then we should first test ourselves (in |
Personally I want the patch as is if it gets us the memory footprint of what we have in the master. I do not see a reason to split it causing more confusion upstream. |
77dcc83
to
f4e61d3
Compare
599e306
to
1b65dcd
Compare
This seems to look good on our side. @smuzaffar would it be possible to run this through CMSSW testing? Thanks in advance! |
cmssw tests are running via cms-sw#221 |
cmssw tests passed cms-sw#221 (comment) |
llvm/llvm-project@20e9049 Update Cling's ExternalASTSourceWrapper to forward the two new LoadExternalSpecializations functions.
Backport upstream PR llvm/llvm-project#133057
Latest numbers:
|
Slightly worse in memory but tolerable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This Pull request:
Use the upstream version of our downstream patch: root-project/llvm-project@a11e943
Ran a few benchmark tests locally, ctests are slightly slower on mine (could just be noise, but nothing concerning)
Will update LLVM tags later once everything is running and good.
This will allow better testing of this patch and will not be coupled with future
LLVM20
updates.Changes or fixes:
Checklist:
This PR fixes #