Skip to content

Commit

Permalink
Merge pull request #1606 from matrix-org/andy/megolm_cache
Browse files Browse the repository at this point in the history
Remove megolm decrypt cache build flag
  • Loading branch information
Anderas authored Oct 17, 2022
2 parents 1689413 + 2a08b43 commit aed6ebb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 57 deletions.
50 changes: 13 additions & 37 deletions MatrixSDK/Crypto/MXOlmDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,10 @@ - (void)upgradeSafetyForSession:(MXOlmInboundGroupSession *)session
[self.store performSessionOperationWithGroupSessionWithId:session.session.sessionIdentifier senderKey:session.senderKey block:^(MXOlmInboundGroupSession *inboundGroupSession) {
inboundGroupSession.untrusted = NO;
}];
if (MXSDKOptions.sharedInstance.enableGroupSessionCache)
@synchronized (self.inboundGroupSessionCache)
{
@synchronized (self.inboundGroupSessionCache)
{
session.untrusted = NO;
[self.inboundGroupSessionCache put:session.session.sessionIdentifier object:session];
}
session.untrusted = NO;
[self.inboundGroupSessionCache put:session.session.sessionIdentifier object:session];
}
}

Expand Down Expand Up @@ -572,34 +569,16 @@ - (MXDecryptionResult *)decryptGroupMessage:(NSString *)body

- (void)performGroupSessionOperationWithSessionId:(NSString*)sessionId senderKey:(NSString*)senderKey block:(void (^)(MXOlmInboundGroupSession *inboundGroupSession))block
{
// Based on a feature flag megolm decryption will either fetch a group session from the store on every decryption,
// or (if the flag is enabled) it will use LRU cache to avoid refetching unchanged sessions.
//
// Additionally the duration of each variant is tracked in analytics (if configured and enabled by the user)
// to allow performance comparison
//
// LRU cache variant will eventually become the default implementation if proved stable.

BOOL enableCache = MXSDKOptions.sharedInstance.enableGroupSessionCache;
NSString *operation = enableCache ? @"megolm.decrypt.cache" : @"megolm.decrypt.store";
StopDurationTracking stopTracking = [MXSDKOptions.sharedInstance.analyticsDelegate startDurationTrackingForName:@"MXOlmDevice" operation:operation];

if (enableCache)
StopDurationTracking stopTracking = [MXSDKOptions.sharedInstance.analyticsDelegate startDurationTrackingForName:@"MXOlmDevice" operation:@"megolm.decrypt.cache"];
@synchronized (self.inboundGroupSessionCache)
{
@synchronized (self.inboundGroupSessionCache)
MXOlmInboundGroupSession *session = (MXOlmInboundGroupSession *)[self.inboundGroupSessionCache get:sessionId];
if (!session)
{
MXOlmInboundGroupSession *session = (MXOlmInboundGroupSession *)[self.inboundGroupSessionCache get:sessionId];
if (!session)
{
session = [store inboundGroupSessionWithId:sessionId andSenderKey:senderKey];
[self.inboundGroupSessionCache put:sessionId object:session];
}
block(session);
session = [store inboundGroupSessionWithId:sessionId andSenderKey:senderKey];
[self.inboundGroupSessionCache put:sessionId object:session];
}
}
else
{
[store performSessionOperationWithGroupSessionWithId:sessionId senderKey:senderKey block:block];
block(session);
}
if (stopTracking)
{
Expand Down Expand Up @@ -711,14 +690,11 @@ - (NSDictionary*)getInboundGroupSessionKey:(NSString*)roomId senderKey:(NSString
- (void)storeInboundGroupSessions:(NSArray <MXOlmInboundGroupSession *>*)sessions
{
[store storeInboundGroupSessions:sessions];
if (MXSDKOptions.sharedInstance.enableGroupSessionCache)
@synchronized (self.inboundGroupSessionCache)
{
@synchronized (self.inboundGroupSessionCache)
for (MXOlmInboundGroupSession *session in sessions)
{
for (MXOlmInboundGroupSession *session in sessions)
{
[self.inboundGroupSessionCache put:session.session.sessionIdentifier object:session];
}
[self.inboundGroupSessionCache put:session.session.sessionIdentifier object:session];
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions MatrixSDK/MXSDKOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,6 @@ NS_ASSUME_NONNULL_BEGIN

#endif

/**
Enable performance optimization where inbound group sessions are cached between decryption of events
rather than fetched from the store every time.
@remark YES by default
*/
@property (nonatomic) BOOL enableGroupSessionCache;

/**
Enable symmetric room key backups
Expand Down
1 change: 0 additions & 1 deletion MatrixSDK/MXSDKOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ - (instancetype)init
_enableCryptoV2 = NO;
#endif

_enableGroupSessionCache = YES;
_enableSymmetricBackup = NO;
_enableNewClientInformationFeature = NO;
}
Expand Down
11 changes: 0 additions & 11 deletions MatrixSDK/MXSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,6 @@ - (void)serverSyncWithServerTimeout:(NSUInteger)serverTimeout
dispatch_group_t initialSyncDispatchGroup = dispatch_group_create();

__block MXTaskProfile *syncTaskProfile;
__block StopDurationTracking stopDurationTracking;
__block MXSyncResponse *syncResponse;
__block BOOL useLiveResponse = YES;

Expand Down Expand Up @@ -1444,13 +1443,6 @@ - (void)serverSyncWithServerTimeout:(NSUInteger)serverTimeout
BOOL isInitialSync = !self.isEventStreamInitialised;
MXTaskProfileName taskName = isInitialSync ? MXTaskProfileNameStartupInitialSync : MXTaskProfileNameStartupIncrementalSync;
syncTaskProfile = [MXSDKOptions.sharedInstance.profiler startMeasuringTaskWithName:taskName];
if (isInitialSync) {
// Temporarily tracking performance both by `MXSDKOptions.sharedInstance.profiler` (manually measuring time)
// and `MXSDKOptions.sharedInstance.analyticsDelegate` (delegating to performance monitoring tool).
// This ambiguity will be resolved in the future
NSString *operation = MXSDKOptions.sharedInstance.enableGroupSessionCache ? @"initialSync.enableGroupSessionCache" : @"initialSync.diableGroupSessionCache";
stopDurationTracking = [MXSDKOptions.sharedInstance.analyticsDelegate startDurationTrackingForName:@"MXSession" operation:operation];
}
}

NSString * streamToken = self.store.eventStreamToken;
Expand Down Expand Up @@ -1493,9 +1485,6 @@ - (void)serverSyncWithServerTimeout:(NSUInteger)serverTimeout
syncTaskProfile.units = syncResponse.rooms.join.count;

[MXSDKOptions.sharedInstance.profiler stopMeasuringTaskWithProfile:syncTaskProfile];
if (stopDurationTracking) {
stopDurationTracking();
}
}

BOOL isInitialSync = !self.isEventStreamInitialised;
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-1606.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Crypto: Remove megolm decrypt cache build flag

0 comments on commit aed6ebb

Please sign in to comment.