From 985f9f9b0785ef01ae81d60aab16565fa4f5fc39 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Fri, 12 Jan 2024 14:44:21 +0000 Subject: [PATCH 1/2] crypto: Improve memory overhead of export_room_keys by using Vec::retain Signed-off-by: Andy Balaam --- crates/matrix-sdk-crypto/src/machine.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 9645441dd8d..df1d7f0d453 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -1830,13 +1830,9 @@ impl OlmMachine { ) -> StoreResult> { let mut exported = Vec::new(); - let sessions: Vec = self - .store() - .get_inbound_group_sessions() - .await? - .into_iter() - .filter(|s| predicate(s)) - .collect(); + let mut sessions = self.store().get_inbound_group_sessions().await?; + + sessions.retain(|s| predicate(s)); for session in sessions { let export = session.export().await; From 7034104ef151afb981656aa0b0c3821339d92d1f Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Mon, 15 Jan 2024 10:03:05 +0000 Subject: [PATCH 2/2] fixup! crypto: Improve memory overhead of export_room_keys by using Vec::retain --- crates/matrix-sdk-crypto/src/machine.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index df1d7f0d453..d79fb9b60ba 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -1826,13 +1826,12 @@ impl OlmMachine { /// ``` pub async fn export_room_keys( &self, - mut predicate: impl FnMut(&InboundGroupSession) -> bool, + predicate: impl FnMut(&InboundGroupSession) -> bool, ) -> StoreResult> { let mut exported = Vec::new(); let mut sessions = self.store().get_inbound_group_sessions().await?; - - sessions.retain(|s| predicate(s)); + sessions.retain(predicate); for session in sessions { let export = session.export().await;