-
Notifications
You must be signed in to change notification settings - Fork 16.1k
[SPGO] Use std::hash instead of MD5 to avoid run time regression in llvm-profgen #180581
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
|
@llvm/pr-subscribers-pgo Author: None (HighW4y2H3ll) Changes#66164 changed the hashing in Can confirm that this patch recovers the run time regression in llvm-profgen, and the perf testing in our internal services shows neutral. Full diff: https://github.com/llvm/llvm-project/pull/180581.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index b75dffaff19f7..8766ab23ac1da 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -522,7 +522,9 @@ struct SampleContextFrame {
}
uint64_t getHashCode() const {
- uint64_t NameHash = Func.getHashCode();
+ // Context frame hash is heavily used in llvm-profgen context-sensitive
+ // pre-inliner. Use a lightweight hashing here to avoid speed regression.
+ uint64_t NameHash = std::hash<std::string>{}(Func.str());
uint64_t LocId = Location.getHashCode();
return NameHash + (LocId << 5) + LocId;
}
|
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
| uint64_t NameHash = Func.getHashCode(); | ||
| // Context frame hash is heavily used in llvm-profgen context-sensitive | ||
| // pre-inliner. Use a lightweight hashing here to avoid speed regression. | ||
| uint64_t NameHash = std::hash<std::string>{}(Func.str()); |
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.
I think we only need to recompute hash when the FunctionId is a string.
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.
ah, good catch.. updated! thx
apolloww
left a comment
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
#66164 changed the hashing in
SampleContextFramefromstd::hashtoMD5in a very hot function (ContextTrieNode::getOrCrateChildContext()) in llvm-profgen. This creates over 2x run time regression when running llvm-profgen with csspgo preinliner enabled, since the MD5 computation is tripled comparing to the Murmur hash in the std library. An llvm-profgen run time comparison shows follows:Can confirm that this patch recovers the run time regression in llvm-profgen, and the perf testing in our internal services shows neutral.