Page MenuHomePhorge

Make tryDecryptEvents() use and update Room::undecryptedEvents
ClosedPublic

Authored by tusooa on Jun 24 2024, 7:23 PM.

Details

Summary

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 ( https://iron.lily-is.land/T20 ) 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

BUG: https://iron.lily-is.land/T20

Test Plan

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

Diff Detail

Repository
rL libkazv
Branch
tusooa/stacked
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 103
Build 195: GitLab CI for libkazv
Build 194: arc lint + arc unit

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.Jul 3 2024, 5:59 PM