llunak created this revision.
llunak added a reviewer: clayborg.
llunak added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
llunak requested review of this revision.
Herald added a subscriber: lldb-commits.
The ordering is not needed, and std::unordered_map is faster (and std::hash for
ConstString is trivial). I can measure time spent in the SaveToCache() calls
reduced to ~50% during LLDB startup (and a ~25% reduction of the total startup
cost).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122980
Files:
lldb/include/lldb/Core/DataFileCache.h
lldb/include/lldb/Utility/ConstString.h
Index: lldb/include/lldb/Utility/ConstString.h
===================================================================
--- lldb/include/lldb/Utility/ConstString.h
+++ lldb/include/lldb/Utility/ConstString.h
@@ -464,6 +464,16 @@
}
} // namespace llvm
+namespace std {
+
+template <> struct hash<lldb_private::ConstString> {
+ std::size_t operator()(const lldb_private::ConstString &str) const {
+ return reinterpret_cast<std::size_t>(str.GetCString());
+ }
+};
+
+} // namespace std
+
LLVM_YAML_IS_SEQUENCE_VECTOR(lldb_private::ConstString)
#endif // LLDB_UTILITY_CONSTSTRING_H
Index: lldb/include/lldb/Core/DataFileCache.h
===================================================================
--- lldb/include/lldb/Core/DataFileCache.h
+++ lldb/include/lldb/Core/DataFileCache.h
@@ -15,6 +15,7 @@
#include "lldb/lldb-forward.h"
#include "llvm/Support/Caching.h"
#include <mutex>
+#include <unordered_map>
namespace lldb_private {
@@ -190,7 +191,7 @@
private:
std::vector<ConstString> m_strings;
- std::map<ConstString, uint32_t> m_string_to_offset;
+ std::unordered_map<ConstString, uint32_t> m_string_to_offset;
/// Skip one byte to start the string table off with an empty string.
uint32_t m_next_offset = 1;
};
Index: lldb/include/lldb/Utility/ConstString.h
===================================================================
--- lldb/include/lldb/Utility/ConstString.h
+++ lldb/include/lldb/Utility/ConstString.h
@@ -464,6 +464,16 @@
}
} // namespace llvm
+namespace std {
+
+template <> struct hash<lldb_private::ConstString> {
+ std::size_t operator()(const lldb_private::ConstString &str) const {
+ return reinterpret_cast<std::size_t>(str.GetCString());
+ }
+};
+
+} // namespace std
+
LLVM_YAML_IS_SEQUENCE_VECTOR(lldb_private::ConstString)
#endif // LLDB_UTILITY_CONSTSTRING_H
Index: lldb/include/lldb/Core/DataFileCache.h
===================================================================
--- lldb/include/lldb/Core/DataFileCache.h
+++ lldb/include/lldb/Core/DataFileCache.h
@@ -15,6 +15,7 @@
#include "lldb/lldb-forward.h"
#include "llvm/Support/Caching.h"
#include <mutex>
+#include <unordered_map>
namespace lldb_private {
@@ -190,7 +191,7 @@
private:
std::vector<ConstString> m_strings;
- std::map<ConstString, uint32_t> m_string_to_offset;
+ std::unordered_map<ConstString, uint32_t> m_string_to_offset;
/// Skip one byte to start the string table off with an empty string.
uint32_t m_next_offset = 1;
};
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits