From 55edbded478de3587374ea1dd3c8a200b758ba40 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Tue, 16 May 2023 09:44:58 -0300 Subject: [PATCH] compaction: avoid excessive reallocation and during input list formatting with off-strategy, input list size can be close to 1k, which will lead to unneeded reallocations when formatting the list for logging. in the past, we faced stalls in this area, and excessive reallocation (log2 ~1k = ~10) may have contributed to that. Signed-off-by: Raphael S. Carvalho Closes #13907 (cherry picked from commit 5544d12f18e9109cdaab5cf384bf477c6ae0a4d9) Fixes scylladb/scylladb#14071 --- compaction/compaction.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compaction/compaction.cc b/compaction/compaction.cc index 7cc00e00aa..dc0ac7e583 100644 --- a/compaction/compaction.cc +++ b/compaction/compaction.cc @@ -414,9 +414,12 @@ private: class formatted_sstables_list { bool _include_origin = true; - std::vector _ssts; + std::vector _ssts; public: formatted_sstables_list() = default; + void reserve(size_t n) { + _ssts.reserve(n); + } explicit formatted_sstables_list(const std::vector& ssts, bool include_origin) : _include_origin(include_origin) { _ssts.reserve(ssts.size()); for (const auto& sst : ssts) { @@ -435,9 +438,7 @@ public: }; std::ostream& operator<<(std::ostream& os, const formatted_sstables_list& lst) { - os << "["; - os << boost::algorithm::join(lst._ssts, ","); - os << "]"; + fmt::print(os, "[{}]", fmt::join(lst._ssts, ",")); return os; } @@ -641,6 +642,7 @@ private: future<> setup() { auto ssts = make_lw_shared(make_sstable_set_for_input()); formatted_sstables_list formatted_msg; + formatted_msg.reserve(_sstables.size()); auto fully_expired = _table_s.fully_expired_sstables(_sstables, gc_clock::now()); min_max_tracker timestamp_tracker;