TraceProcessor: use base::FlatHashMap<> where possible
Saves ~10s (~10%) ingestion time
Before: Trace loaded: 4193.25 MB (39.2 MB/s, 106.97 s)
After: Trace loaded: 4193.25 MB (43.6 MB/s, 96.22 s)
Bug: 205302474
Change-Id: I6166f57710b2aeb2617765a727ce133c3297e7ae
diff --git a/src/trace_processor/containers/string_pool.cc b/src/trace_processor/containers/string_pool.cc
index fd65195..0189054 100644
--- a/src/trace_processor/containers/string_pool.cc
+++ b/src/trace_processor/containers/string_pool.cc
@@ -53,8 +53,8 @@
StringPool::~StringPool() = default;
-StringPool::StringPool(StringPool&&) = default;
-StringPool& StringPool::operator=(StringPool&&) = default;
+StringPool::StringPool(StringPool&&) noexcept = default;
+StringPool& StringPool::operator=(StringPool&&) noexcept = default;
StringPool::Id StringPool::InsertString(base::StringView str, uint64_t hash) {
// Try and find enough space in the current block for the string and the
@@ -70,9 +70,8 @@
// new block to store the string.
if (str.size() + kMaxMetadataSize >= kMinLargeStringSizeBytes) {
return InsertLargeString(str, hash);
- } else {
- blocks_.emplace_back(kBlockSizeBytes);
}
+ blocks_.emplace_back(kBlockSizeBytes);
// Try and reserve space again - this time we should definitely succeed.
std::tie(success, offset) = blocks_.back().TryInsert(str);
@@ -82,7 +81,11 @@
// Compute the id from the block index and offset and add a mapping from the
// hash to the id.
Id string_id = Id::BlockString(blocks_.size() - 1, offset);
- string_index_.emplace(hash, string_id);
+
+ // Deliberately not adding |string_id| to |string_index_|. The caller
+ // (InternString()) must take care of this.
+ PERFETTO_DCHECK(string_index_.Find(hash));
+
return string_id;
}
@@ -91,7 +94,11 @@
large_strings_.emplace_back(new std::string(str.begin(), str.size()));
// Compute id from the index and add a mapping from the hash to the id.
Id string_id = Id::LargeString(large_strings_.size() - 1);
- string_index_.emplace(hash, string_id);
+
+ // Deliberately not adding |string_id| to |string_index_|. The caller
+ // (InternString()) must take care of this.
+ PERFETTO_DCHECK(string_index_.Find(hash));
+
return string_id;
}