matrix-org / matrix-rust-sdk

Matrix Client-Server SDK for Rust
Apache License 2.0
1.26k stars 252 forks source link

Improve performance of encrypted sqlite DB #3697

Open kegsay opened 4 months ago

kegsay commented 4 months ago

As seen in https://github.com/matrix-org/complement-crypto/pull/122 which times out due to how slow it gets with encryption enabled via .Passphrase being set on the client_builder.

Example timings:

This is 3-5x worse.

This means I can't realistically enable encrypted DBs in tests, which is desirable in order to match EX.

poljar commented 4 months ago

I think that this is mostly due to our PBKDF usage in the default case when we encrypt the store. The usage of a random key is possible with our primitive itself:

https://github.com/matrix-org/matrix-rust-sdk/blob/7a85b7abdcfc05881ccbddf54a2094273be90110/crates/matrix-sdk-store-encryption/src/lib.rs#L151-L182

But it's not easily exposed in the ClientBuilder like the passphrase based mechanism is:

https://github.com/matrix-org/matrix-rust-sdk/blob/7a85b7abdcfc05881ccbddf54a2094273be90110/crates/matrix-sdk/src/client/builder.rs#L216-L228

We would need a new method to let us create stores with a random key instead.