[Lldb-commits] [PATCH] D122980: make ConstStringTable use std::unordered_map rather than std::map
Luboš Luňák via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sat Apr 2 08:24:17 PDT 2022
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;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122980.419987.patch
Type: text/x-patch
Size: 1244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220402/d2e0436a/attachment.bin>
More information about the lldb-commits
mailing list