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

Cache inbound group sessions when decrypting #1566

Merged
merged 5 commits into from
Aug 31, 2022
Merged

Conversation

Anderas
Copy link
Contributor

@Anderas Anderas commented Aug 26, 2022

Improve megolm event decryption behaviour by caching rather than re-fetching inbounds group sessions from the store. In anecdotal comparison on a single device this leads to 5x - 10x performance improvement.

In order to observe the impact of this improvement more precisely, the following changes are made:

  • add build flag that randomly selects between new cache behaviour and old fetch behaviour, which will result in a very basic form of A/B test
  • add duration tracking to analytics to measure the difference between both (this is performed by Sentry in element-ios)
  • add duration tracking for MXSession.initialSync which calls megolm decrypt methods

Note that the new performance tracking method conflicts with existing MXProfiler which does the time tracking manually, whereas Sentry handles performance measurements internally. This ambiguity will be resolved in a future PR

Once in Sentry, the following dashboards can be constructed from these events:

Screenshot 2022-08-26 at 16 33 33

@Anderas Anderas requested review from manuroe and a team August 26, 2022 15:31
Copy link
Contributor

@manuroe manuroe left a comment

Choose a reason for hiding this comment

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

This A/B performance testing is really great!

I was not comfortable with the word cancel at first. I thought it was for abortion. This is why I asked for some renaming.

MatrixSDK/Crypto/MXOlmDevice.m Show resolved Hide resolved
Enable performance optimization where inbound group sessions are cached between decryption of events
rather than fetched from the store every time.

@remark The value is set randomly between YES / NO to perform a very basic A/B test
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@remark The value is set randomly between YES / NO to perform a very basic A/B test
@remark By default, the value is set randomly between YES / NO to perform a very basic A/B test

@@ -20,6 +20,12 @@
#import "MXCallHangupEventContent.h"
#import "MXTaskProfile.h"

/**
Callback function to cancel ongoing duration tracking
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Callback function to cancel ongoing duration tracking
Callback function to finish ongoing duration tracking

@@ -46,6 +52,21 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)trackDuration:(NSInteger)milliseconds name:(MXTaskProfileName)name units:(NSUInteger)units;

/**
Start tracking the duration of a task and manually cancel when finished using the return handle
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Start tracking the duration of a task and manually cancel when finished using the return handle
Start tracking the duration of a task and manually stop when finished using the return handle

@Anderas Anderas requested a review from manuroe August 30, 2022 10:59
@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2022

Codecov Report

Merging #1566 (02b3541) into develop (9d6ef50) will increase coverage by 0.05%.
The diff coverage is 78.84%.

@@             Coverage Diff             @@
##           develop    #1566      +/-   ##
===========================================
+ Coverage    45.16%   45.22%   +0.05%     
===========================================
  Files          521      521              
  Lines        84960    85009      +49     
  Branches     37510    37534      +24     
===========================================
+ Hits         38373    38445      +72     
+ Misses       45486    45459      -27     
- Partials      1101     1105       +4     
Impacted Files Coverage Δ
MatrixSDK/MXSession.m 48.35% <62.50%> (+0.03%) ⬆️
MatrixSDK/Crypto/MXOlmDevice.m 80.27% <81.39%> (-0.03%) ⬇️
MatrixSDK/MXSDKOptions.m 100.00% <100.00%> (ø)
MatrixSDK/Background/MXBackgroundCryptoStore.m 28.18% <0.00%> (-3.86%) ⬇️
...Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m 64.82% <0.00%> (-1.50%) ⬇️
.../RoomList/MXStore/MXStoreRoomListDataFetcher.swift 70.35% <0.00%> (-1.33%) ⬇️
...rypto/KeySharing/MXOutgoingRoomKeyRequestManager.m 73.70% <0.00%> (-0.94%) ⬇️
MatrixSDK/Space/MXSpaceService.swift 75.22% <0.00%> (+0.45%) ⬆️
...yncResponseFileStore/MXSyncResponseFileStore.swift 91.32% <0.00%> (+1.53%) ⬆️
MatrixSDKTests/MXHTTPAdditionalHeadersUnitTests.m 85.10% <0.00%> (+12.76%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Anderas Anderas merged commit d53c0f5 into develop Aug 31, 2022
@Anderas Anderas deleted the andy/cached_megolm branch August 31, 2022 09:38
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.

3 participants