element-hq / element-web

A glossy Matrix collaboration client for the web.
https://element.io
Apache License 2.0
10.74k stars 1.89k forks source link

batching of `m.room_key` to-device messages is suboptimal #24680

Closed richvdh closed 2 weeks ago

richvdh commented 1 year ago

When we send out m.room_key messages to share a new encryption session, we attempt to batch those messages into groups of 20 per call to /sendToDevice. However the batching logic is distinctly suboptimal and we often end up creating much smaller batches.

I'm also not really sure why 20 was chosen as the target.

This leads to lots of requests to the /sendToDevice endpoint and general slowness in sending out room keys, potentially causing unable-to-decrypt errors (https://github.com/vector-im/element-meta/issues/245) and causing the recipient to start sending out m.room_key_request messages, exacerbating the problem.

richvdh commented 1 year ago

Likely we will fix this as part of https://github.com/vector-im/element-web/issues/21972 rather than spending time fixing it in an implementation that will be thrown away.

BillCarsonFr commented 3 months ago

Rust SDK limit is set to 250

Added a task in regression test list to later implement.

richvdh commented 3 months ago

Rust SDK limit is set to 250

... and, more importantly, its batching logic looks sensible

kegsay commented 2 months ago

Pending complement-crypto test to check that we batch in as large a chunk as possible i.e 250.

kegsay commented 2 weeks ago

This was done.