From 3b2b34f43dbf0e5ae598ac5e1ed5d702506e138d Mon Sep 17 00:00:00 2001 From: Ivan Morozko Date: Sat, 5 Oct 2024 21:02:11 +0400 Subject: [PATCH] Increase performance of AccumulateClues by preallocating and utilizing try_emplace --- src/core/algorithms/dc/FastADC/util/clue_set_builder.h | 5 ++++- .../algorithms/dc/FastADC/util/common_clue_set_builder.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/algorithms/dc/FastADC/util/clue_set_builder.h b/src/core/algorithms/dc/FastADC/util/clue_set_builder.h index bcd36f623d..4670dea360 100644 --- a/src/core/algorithms/dc/FastADC/util/clue_set_builder.h +++ b/src/core/algorithms/dc/FastADC/util/clue_set_builder.h @@ -24,7 +24,10 @@ inline ClueSet BuildClueSet(std::vector const& pliShards, PredicatePac } for (auto const& [clue, count] : partial_clue_set) { - clue_set[clue] += count; + auto [it, inserted] = clue_set.try_emplace(clue, count); + if (!inserted) { + it->second += count; + } } } } diff --git a/src/core/algorithms/dc/FastADC/util/common_clue_set_builder.h b/src/core/algorithms/dc/FastADC/util/common_clue_set_builder.h index 25c885ed56..2b5f94a49a 100644 --- a/src/core/algorithms/dc/FastADC/util/common_clue_set_builder.h +++ b/src/core/algorithms/dc/FastADC/util/common_clue_set_builder.h @@ -35,12 +35,15 @@ ClueSet AccumulateClues(Vectors const&... vectors) { ClueSet clue_set; int64_t clue_zero_count = 0; + clue_set.reserve((vectors.size() + ...)); + auto insert_clues = [&](std::vector const& clues) { for (auto const& clue : clues) { if (clue.none()) { ++clue_zero_count; } else { - clue_set[clue]++; + auto [it, inserted] = clue_set.try_emplace(clue, 1); + if (!inserted) it->second++; } } };