From e1261d10f17c2d219f159c01ddf7fd2b122f9d6a Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Fri, 5 Feb 2021 15:20:28 -0300 Subject: [PATCH] table: Avoid useless allocations when updating cache on memtable flush completion we're unconditionally using make_combined_mutation_source(), which causes extra allocations, even if memtable was flushed into a single sstable, which is the most common case. memtable will only be flushed into more than one sstable if TWCS is used and memtable had old data written into it due to out-of-order writes. Signed-off-by: Raphael S. Carvalho Message-Id: <20210205182028.439948-1-raphaelsc@scylladb.com> --- table.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/table.cc b/table.cc index a0db72862a..7c1d5e42d9 100644 --- a/table.cc +++ b/table.cc @@ -389,13 +389,18 @@ table::add_sstable_and_update_cache(sstables::shared_sstable sst) { future<> table::update_cache(lw_shared_ptr m, std::vector ssts) { - std::vector sources; - sources.reserve(ssts.size()); - for (auto& sst : ssts) { - sources.push_back(sst->as_mutation_source()); + mutation_source_opt ms_opt; + if (ssts.size() == 1) { + ms_opt = ssts.front()->as_mutation_source(); + } else { + std::vector sources; + sources.reserve(ssts.size()); + for (auto& sst : ssts) { + sources.push_back(sst->as_mutation_source()); + } + ms_opt = make_combined_mutation_source(std::move(sources)); } - auto new_ssts_ms = make_combined_mutation_source(std::move(sources)); - auto adder = row_cache::external_updater([this, m, ssts = std::move(ssts), new_ssts_ms = std::move(new_ssts_ms)] () mutable { + auto adder = row_cache::external_updater([this, m, ssts = std::move(ssts), new_ssts_ms = std::move(*ms_opt)] () mutable { for (auto& sst : ssts) { add_sstable(sst); }