Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: Improve memory overhead of export_room_keys by using Vec::retain #3013

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

andybalaam
Copy link
Member

As I understand it, Vec::retain should do the same job as into_iter().filter().collect() but potentially more efficiently. This could help our problem with running out of memory during export ( #2914 ).

@andybalaam andybalaam requested a review from a team as a code owner January 12, 2024 14:58
@andybalaam andybalaam requested review from Hywan and removed request for a team January 12, 2024 14:58
@andybalaam andybalaam force-pushed the andybalaam/retain-in-export_room_keys branch from 7502dc0 to 985f9f9 Compare January 12, 2024 15:05
Copy link

codecov bot commented Jan 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3fea9ae) 83.47% compared to head (7034104) 83.47%.
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3013      +/-   ##
==========================================
- Coverage   83.47%   83.47%   -0.01%     
==========================================
  Files         222      222              
  Lines       23213    23212       -1     
==========================================
- Hits        19378    19376       -2     
- Misses       3835     3836       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks 👍

It might avoid double-buffering for the entries of Vec<InboundGroupSession> indeed; I'd expect one issue is that get_inbound_group_sessions will still allocate all the sessions while we're discarding some of them. If get_inbound_group_sessions returned an iterator, we could filter out without even allocating the vector, which would be optimal.

crates/matrix-sdk-crypto/src/machine.rs Outdated Show resolved Hide resolved
@bnjbvr bnjbvr removed the request for review from Hywan January 12, 2024 16:34
@andybalaam
Copy link
Member Author

If get_inbound_group_sessions returned an iterator

Yes, although I think it would need to be a stream because it's async. I may move on to doing this soonish, if it is needed to fix #2914

@andybalaam andybalaam enabled auto-merge January 15, 2024 10:08
@andybalaam andybalaam merged commit 58be7b0 into main Jan 15, 2024
34 checks passed
@andybalaam andybalaam deleted the andybalaam/retain-in-export_room_keys branch January 15, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants