Skip to content

Commit f367eaa

Browse files
[memprof] Add accessors to Frame::SymbolName (#94085)
This patch adds accessors to Frame::SymbolName so that we can change the underlying type of SymbolName without affecting downstream users once they switch to the new accessors. Note that SymbolName is only used for debugging. Changing the type of SymbolName from std::optional<std::string> to std::unique_ptr<std::string> cuts down sizeof(Frame) by half -- from 64 bytes to 32 bytes. (std::optional<T> sets aside the storage in case T is instantiated.) During deserialization, the memory usage is dominated by Frames. Shrinking the type cuts down the memory usage and deserialization time nearly by half.
1 parent 718331f commit f367eaa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ struct Frame {
237237

238238
bool operator!=(const Frame &Other) const { return !operator==(Other); }
239239

240+
bool hasSymbolName() const { return SymbolName.has_value(); }
241+
242+
StringRef getSymbolName() const {
243+
assert(SymbolName.has_value());
244+
return *SymbolName;
245+
}
246+
247+
std::string getSymbolNameOr(StringRef Alt) const {
248+
return std::string(hasSymbolName() ? getSymbolName() : Alt);
249+
}
250+
240251
// Write the contents of the frame to the ostream \p OS.
241252
void serialize(raw_ostream &OS) const {
242253
using namespace support;
@@ -279,7 +290,7 @@ struct Frame {
279290
void printYAML(raw_ostream &OS) const {
280291
OS << " -\n"
281292
<< " Function: " << Function << "\n"
282-
<< " SymbolName: " << SymbolName.value_or("<None>") << "\n"
293+
<< " SymbolName: " << getSymbolNameOr("<None>") << "\n"
283294
<< " LineOffset: " << LineOffset << "\n"
284295
<< " Column: " << Column << "\n"
285296
<< " Inline: " << IsInlineFrame << "\n";

0 commit comments

Comments
 (0)