Reserve memory for the identifiers hashtable. (#4107)

This uses a heuristic reserve to greatly reduce hashtable growth of the
identifiers hashtable. The design of the hashtable itself is optimized
around compact memory use and is especially slow to grow and so this has
an outsized impact.

The heuristic was computed using `scripts/source_stats.py` and looking
at C++ codebases. We may want to periodically re-evaluate it as Carbon
code emerges and we have better data on its distributions of tokens.

This also required fixing the `Reserve` method on `CanonicalValueStore`
that wasn't actually used anywhere and so didn't even compile correctly.
I added it to the relevant unit test so it is at least compiled locally
to its definition.
This commit is contained in:
Chandler Carruth
2024-07-18 15:41:21 +00:00
committed by GitHub
parent 1ed58895bc
commit 44c85e0872
3 changed files with 62 additions and 8 deletions
+3
View File
@@ -82,6 +82,9 @@ TEST(ValueStore, Identifiers) {
std::string b = "b";
SharedValueStores value_stores;
// Make sure reserve works, we use it with identifiers.
value_stores.identifiers().Reserve(100);
auto a_id = value_stores.identifiers().Add(a);
auto b_id = value_stores.identifiers().Add(b);