Page MenuHomePhorge

Make tryDecryptEvents() use and update Room::undecryptedEvents

Authored by tusooa on Jun 24 2024, 7:23 PM.
Referenced Files
Unknown Object (File)
Tue, Jul 23, 4:19 AM
Unknown Object (File)
Tue, Jul 23, 4:19 AM
Unknown Object (File)
Tue, Jul 23, 4:19 AM
Unknown Object (File)
Tue, Jul 23, 12:45 AM
Unknown Object (File)
Sun, Jul 21, 8:24 PM
Unknown Object (File)
Sun, Jul 21, 10:37 AM
Unknown Object (File)
Sat, Jul 20, 4:31 PM
Unknown Object (File)
Fri, Jul 19, 4:34 AM



The original way is to go and check every event in a room to see whether they can be decrypted. Now that we have a map from session id to a list of undecrypted event ids, this commit provides two optimizations:

  1. It only needs to check undecrypted events, which is sparse compared to the whole timeline.
  2. It checks the existence of the session id, and if it does not exist, we do not try to decrypt the events with that session id. We expect this to further decrease the number of trials needed by at least the magnitude of 10 in one-on-one rooms (100 messages to rotate sessions, so assuming 10 devices per person, it's on average 10 messages per session id).

The benchmark results ( ) show that the new method will give <200ms performance per call even on extremely large and infeasible data sets, compared to ~4.4s for the original, sequential method. (For reference, the medium set is already pretty large (total of 50k events in encrypted rooms))

In the future, when we immerify kazvcrypto, we can use diff on the map of megolm sessions to further reduce the checks needed by checking only new events and session ids that have been changed.

Type: fix


Test Plan

Verify that all tests pass. Build kazv against this. Verify that you can still send and receive encrypted messages.

Diff Detail

rL libkazv
Lint Not Applicable
Tests Not Applicable

Event Timeline

For reference, I used to get ~1s delay between sending a message (from another account) and getting a notification on my main account. It is now almost instantaneous.

Harbormaster returned this revision to the author for changes because remote builds failed.Jun 24 2024, 7:55 PM
Harbormaster failed remote builds in B102: Diff 152!
This revision is now accepted and ready to land.Wed, Jul 3, 5:59 PM