Speedup sending encrypted messages after metasync was reenabled

Calling fsync everytime we save to the db is slow, which is actually
fairly noticeable in some larger E2EE rooms. Speed that up slightly by
batching the olm session persisting.
This commit is contained in:
Nicolas Werner 2022-11-01 20:58:01 +01:00
parent ee1a219661
commit 676a6506cb
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 109 additions and 73 deletions

View file

@ -912,6 +912,29 @@ Cache::getMegolmSessionData(const MegolmSessionIndex &index)
// OLM sessions.
//
void
Cache::saveOlmSessions(std::vector<std::pair<std::string, mtx::crypto::OlmSessionPtr>> sessions,
uint64_t timestamp)
{
using namespace mtx::crypto;
auto txn = lmdb::txn::begin(env_);
for (const auto &[curve25519, session] : sessions) {
auto db = getOlmSessionsDb(txn, curve25519);
const auto pickled = pickle<SessionObject>(session.get(), pickle_secret_);
const auto session_id = mtx::crypto::session_id(session.get());
StoredOlmSession stored_session;
stored_session.pickled_session = pickled;
stored_session.last_message_ts = timestamp;
db.put(txn, session_id, nlohmann::json(stored_session).dump());
}
txn.commit();
}
void
Cache::saveOlmSession(const std::string &curve25519,
mtx::crypto::OlmSessionPtr session,