Commit 1e559553 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Avoid pointless dynamic allocation in hot path

parent 90c19702
......@@ -108,10 +108,11 @@ void RaftCommitTracker::recalculateCommitIndex() {
// a RaftMatchIndexTracker on it. But it has to be taken into account in the
// commitIndex calculation.
std::vector<LogIndex> matchIndexes;
matchIndexes.resize(targets.size());
size_t i = 0;
for(auto it = targets.begin(); it != targets.end(); it++) {
matchIndexes.push_back(it->second->get());
matchIndexes[i++] = it->second->get();
}
std::sort(matchIndexes.begin(), matchIndexes.end());
......
......@@ -67,6 +67,7 @@ private:
std::map<RaftServer, RaftMatchIndexTracker*> registrations;
std::map<RaftServer, RaftMatchIndexTracker*> targets;
std::vector<LogIndex> matchIndexes;
LogIndex commitIndex = 0;
bool commitIndexLagging = false;
......
......@@ -41,7 +41,7 @@ TEST_F(AllocationCount, 30k_entries) {
std::vector<std::future<redisReplyPtr>> futures;
const int64_t NENTRIES = 30000;
constexpr int64_t NENTRIES = 5000000;
for(size_t i = 0; i < NENTRIES; i++) {
futures.emplace_back(tunnel(leaderID)->exec("set", SSTR("key-" << i), SSTR("value-" << i)));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment