export: Add a streamed way of getting room keys #3144
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is part of my work on reducing the memory usage of exporting all our room keys #2914.
It's small part: we offer a streamed method on
OlmMachine
calledexport_room_keys_stream
that is similar toexport_room_keys
except it returns aStream
, meaning the caller does not need to have all the keys they requested in memory at the same time.Inside its implementation, it uses
CryptoStore::get_inbound_group_sessions
, which returns aVec
, so it doesn't (yet) prevent unbounded memory use.In a test I did with 10K keys, when I used this method and serialised the result directly to JSON without holding it in an intermediate
Vec
I saw a few MB of memory savings in Element Web during export.So there is some immediate benefit, but possibly more importantly, this just feels like the right interface to offer: especially when we are exporting all keys, we don't want to be forced to hold them all in a
Vec
asexport_room_keys
does. In future, some PR like #3060 will allow us to stream properly from the database, and not hold all keys in an intermediateVec
as we do now.I plan to follow this up with a PR in
matrix-rust-sdk-crypto-wasm
that realises the memory saving I referred to above.