-
Notifications
You must be signed in to change notification settings - Fork 731
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
Improve usage of realm #5297
Improve usage of realm #5297
Conversation
Matrix SDKIntegration Tests Results:
|
if (bgRealm.isInTransaction) { | ||
bgRealm.cancelTransaction() | ||
} | ||
return withContext(Realm.WRITE_EXECUTOR.asCoroutineDispatcher()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth holding onto the Realm.WRITE_EXECUTOR.asCoroutineDispatcher()
instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, at least realm is not doing that neither
@@ -90,8 +90,7 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity, | |||
private val timelineEventsChangeListener = | |||
OrderedRealmCollectionChangeListener { results: RealmResults<TimelineEventEntity>, changeSet: OrderedCollectionChangeSet -> | |||
Timber.v("on timeline events chunk update") | |||
val frozenResults = results.freeze() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main fix ^ =P
.mapNotNull { | ||
val roomMember = RoomMemberSummaryEntity.where(readReceiptsSummaryEntity.realm, roomId = it.roomId, userId = it.userId).findFirst() | ||
?: return@mapNotNull null | ||
ReadReceipt(roomMember.asDomain(), it.originServerTs.toLong()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any side effects from switching User
to RoomMember
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User avatar can be set per room, so maybe there will be a visible effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this should just fix some cases where user has changed avatar/name only in the room
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some questions for my own understanding but the code changes look sound! 💯
testing locally, I didn't see much change in realm allocations unfortunately (although that wasn't the goal of this PR so it's expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (static review)
ktlint is not happy, can you have a look please?
That's sad, we will have to continue digging on that point |
Type of change
Content
This PR removes usage of frozen RealmResults in the timeline, as it wasn't necessary (not switch of threads)
Also uses Realm.WRITE_EXECUTOR for awaitTransaction.
Last, not really related to realm but took the opportunity to replace ReadReceipt.User by ReadReceipt.RoomMember as we are in a room.
Motivation and context
Improves performance of realm, and reduce the consumption of disk space (before compacting) and probably ram usage.
Tests
Tested devices