Stop using Map for the cache in InstFingerprinter (#6019)

This takes the debug runtime of
`toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon`
from 4.7s down to about 4s (so 15% faster overall).

There's still lots of room to improve this test which seems to be
hitting lots of pathological behaviour, but InstNamer is 30% of the
runtime, with fingerprinting's `InstFingerprinter::GetOrCompute`
consuming 10% of cycles. We reduce its impact by using a vector of
vectors instead of a Map for the cache of fingerprints. After this
change InstNamer drops below 24% of the runtime.

Also move the instruction name when giving it to `AllocateName` since it
receives std::string by value, though this doesn't show up in the
profile for the test.
This commit is contained in:
Dana Jansens
2025-09-08 16:15:10 +00:00
committed by GitHub
parent 471b394c6d
commit 64139e5d65
21 changed files with 118 additions and 44 deletions
+2 -1
View File
@@ -154,6 +154,7 @@ auto Context::File::SetText(Context& context, std::optional<int64_t> version,
.value_stores = value_stores_.get(),
.timings = nullptr,
.sem_ir = &sem_ir,
.total_ir_count = 1,
.clang_ast_unit = &clang_ast_unt}}};
auto getter = [this]() -> const Parse::TreeAndSubtrees& {
@@ -163,7 +164,7 @@ auto Context::File::SetText(Context& context, std::optional<int64_t> version,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
llvm::vfs::getRealFileSystem();
// TODO: Include the prelude.
// TODO: Include the prelude. Make sure `total_ir_count` includes the files.
Check::CheckParseTreesOptions check_options;
check_options.vlog_stream = context.vlog_stream();
auto getters =