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

Use export_room_keys_stream to reduce export memory usage #105

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

andybalaam
Copy link
Member

@andybalaam andybalaam commented Feb 20, 2024

Applies on top of #106

Make use of the new export_room_keys_stream method from matrix-org/matrix-rust-sdk#3144 to avoid one copy of the keys in the export process, by directly serialising to a JSON string, without taking the intermediate step into a Vec<ExportedRoomKey>.

Part of element-hq/element-web#26681

@andybalaam andybalaam force-pushed the andybalaam/export-as-stream branch from 331474c to bcc13c2 Compare February 20, 2024 15:29
@andybalaam andybalaam changed the base branch from main to andybalaam/update-rust-sdk-for-export_room_keys_stream February 20, 2024 15:30
@andybalaam andybalaam marked this pull request as ready for review February 20, 2024 15:40
@andybalaam andybalaam requested a review from a team as a code owner February 20, 2024 15:40
@andybalaam andybalaam requested review from bnjbvr and removed request for a team February 20, 2024 15:40
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.

lgtm. Is it already tested or could it benefit from a new test, at least validating what the return type actually is? Thanks!

src/machine.rs Outdated Show resolved Hide resolved
src/machine.rs Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
T: Serialize,
S: Stream<Item = T>,
{
let mut stream_json = vec![];
Copy link
Member

Choose a reason for hiding this comment

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

Would initializing with an initial capacity make sense? Assuming the stream's not empty, we can likely avoid many reallocations by having a large initial size here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, but I don't know how to estimate a good size here. Do we do anything similar anywhere else in the code? Do we have any rules of thumb?

Base automatically changed from andybalaam/update-rust-sdk-for-export_room_keys_stream to main February 21, 2024 12:30
@andybalaam
Copy link
Member Author

lgtm. Is it already tested or could it benefit from a new test, at least validating what the return type actually is? Thanks!

It's already tested in machine.test.ts.

@andybalaam andybalaam force-pushed the andybalaam/export-as-stream branch from bcc13c2 to 0861298 Compare February 21, 2024 15:14
@andybalaam andybalaam force-pushed the andybalaam/export-as-stream branch from 0861298 to 66c6ddf Compare February 21, 2024 15:15
@andybalaam andybalaam enabled auto-merge February 21, 2024 15:16
@andybalaam andybalaam merged commit 22b56cb into main Feb 21, 2024
3 checks passed
@andybalaam andybalaam deleted the andybalaam/export-as-stream branch February 21, 2024 15:19
andybalaam added a commit to matrix-org/matrix-js-sdk that referenced this pull request Feb 22, 2024
github-merge-queue bot pushed a commit to matrix-org/matrix-js-sdk that referenced this pull request Feb 22, 2024
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