Commit 5856733cc91c10ab19e90fdaeb81c5c486c8952a

Authored by Wiebe Cazemier
1 parent 295cf8ee

Change sessions copy from list to vector when saving

When there are many sessions, the copying action can actually take some
time, and memory. A vector is faster and uses (a little) less memory.

This is a theoretical fix, without benchmarks to support it.
sessionsandsubscriptionsdb.cpp
@@ -183,7 +183,7 @@ void SessionsAndSubscriptionsDB::writeRowHeader() @@ -183,7 +183,7 @@ void SessionsAndSubscriptionsDB::writeRowHeader()
183 183
184 } 184 }
185 185
186 -void SessionsAndSubscriptionsDB::saveData(const std::list<std::unique_ptr<Session>> &sessions, const std::unordered_map<std::string, std::list<SubscriptionForSerializing>> &subscriptions) 186 +void SessionsAndSubscriptionsDB::saveData(const std::vector<std::unique_ptr<Session>> &sessions, const std::unordered_map<std::string, std::list<SubscriptionForSerializing>> &subscriptions)
187 { 187 {
188 if (!f) 188 if (!f)
189 return; 189 return;
sessionsandsubscriptionsdb.h
@@ -64,7 +64,7 @@ public: @@ -64,7 +64,7 @@ public:
64 void openWrite(); 64 void openWrite();
65 void openRead(); 65 void openRead();
66 66
67 - void saveData(const std::list<std::unique_ptr<Session>> &sessions, const std::unordered_map<std::string, std::list<SubscriptionForSerializing>> &subscriptions); 67 + void saveData(const std::vector<std::unique_ptr<Session>> &sessions, const std::unordered_map<std::string, std::list<SubscriptionForSerializing>> &subscriptions);
68 SessionsAndSubscriptionsResult readData(); 68 SessionsAndSubscriptionsResult readData();
69 }; 69 };
70 70
subscriptionstore.cpp
@@ -639,7 +639,8 @@ void SubscriptionStore::saveSessionsAndSubscriptions(const std::string &amp;filePath @@ -639,7 +639,8 @@ void SubscriptionStore::saveSessionsAndSubscriptions(const std::string &amp;filePath
639 639
640 // First copy the sessions... 640 // First copy the sessions...
641 641
642 - std::list<std::unique_ptr<Session>> sessionCopies; 642 + std::vector<std::unique_ptr<Session>> sessionCopies;
  643 + sessionCopies.reserve(sessionsByIdConst.size());
643 644
644 for (const auto &pair : sessionsByIdConst) 645 for (const auto &pair : sessionsByIdConst)
645 { 646 {