removing some old time measuring code for additional performance.

This commit is contained in:
Vitor Pamplona
2023-12-15 15:30:16 -05:00
parent 2dc23b601a
commit 23fad2a818
6 changed files with 120 additions and 173 deletions
@@ -7,7 +7,6 @@ import com.vitorpamplona.amethyst.ui.actions.updated
import com.vitorpamplona.quartz.events.ChannelMessageEvent import com.vitorpamplona.quartz.events.ChannelMessageEvent
import com.vitorpamplona.quartz.events.ChatroomKey import com.vitorpamplona.quartz.events.ChatroomKey
import com.vitorpamplona.quartz.events.ChatroomKeyable import com.vitorpamplona.quartz.events.ChatroomKeyable
import kotlin.time.measureTimedValue
class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter<Note>() { class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter<Note>() {
@@ -46,58 +45,53 @@ class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter<Not
} }
override fun updateListWith(oldList: List<Note>, newItems: Set<Note>): List<Note> { override fun updateListWith(oldList: List<Note>, newItems: Set<Note>): List<Note> {
val (feed, elapsed) = measureTimedValue { val me = account.userProfile()
val me = account.userProfile()
// Gets the latest message by channel from the new items. // Gets the latest message by channel from the new items.
val newRelevantPublicMessages = filterRelevantPublicMessages(newItems, account) val newRelevantPublicMessages = filterRelevantPublicMessages(newItems, account)
// Gets the latest message by room from the new items. // Gets the latest message by room from the new items.
val newRelevantPrivateMessages = filterRelevantPrivateMessages(newItems, account) val newRelevantPrivateMessages = filterRelevantPrivateMessages(newItems, account)
if (newRelevantPrivateMessages.isEmpty() && newRelevantPublicMessages.isEmpty()) { if (newRelevantPrivateMessages.isEmpty() && newRelevantPublicMessages.isEmpty()) {
return oldList return oldList
}
var myNewList = oldList
newRelevantPublicMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote ->
if (newNotePair.key == oldNote.channelHex()) {
hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value)
}
}
}
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
newRelevantPrivateMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote ->
val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
if (newNotePair.key == oldRoom) {
hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value)
}
}
}
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
sort(myNewList.toSet()).take(1000)
} }
// Log.d("Time", "${this.javaClass.simpleName} Modified Additive Feed in $elapsed with ${feed.size} objects") var myNewList = oldList
return feed
newRelevantPublicMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote ->
if (newNotePair.key == oldNote.channelHex()) {
hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value)
}
}
}
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
newRelevantPrivateMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote ->
val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
if (newNotePair.key == oldRoom) {
hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value)
}
}
}
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
return sort(myNewList.toSet()).take(1000)
} }
override fun applyFilter(newItems: Set<Note>): Set<Note> { override fun applyFilter(newItems: Set<Note>): Set<Note> {
@@ -6,7 +6,6 @@ import com.vitorpamplona.amethyst.ui.actions.updated
import com.vitorpamplona.quartz.events.ChatroomKey import com.vitorpamplona.quartz.events.ChatroomKey
import com.vitorpamplona.quartz.events.ChatroomKeyable import com.vitorpamplona.quartz.events.ChatroomKeyable
import com.vitorpamplona.quartz.events.PrivateDmEvent import com.vitorpamplona.quartz.events.PrivateDmEvent
import kotlin.time.measureTimedValue
class ChatroomListNewFeedFilter(val account: Account) : AdditiveFeedFilter<Note>() { class ChatroomListNewFeedFilter(val account: Account) : AdditiveFeedFilter<Note>() {
@@ -36,40 +35,35 @@ class ChatroomListNewFeedFilter(val account: Account) : AdditiveFeedFilter<Note>
} }
override fun updateListWith(oldList: List<Note>, newItems: Set<Note>): List<Note> { override fun updateListWith(oldList: List<Note>, newItems: Set<Note>): List<Note> {
val (feed, elapsed) = measureTimedValue { val me = account.userProfile()
val me = account.userProfile()
// Gets the latest message by room from the new items. // Gets the latest message by room from the new items.
val newRelevantPrivateMessages = filterRelevantPrivateMessages(newItems, account) val newRelevantPrivateMessages = filterRelevantPrivateMessages(newItems, account)
if (newRelevantPrivateMessages.isEmpty()) { if (newRelevantPrivateMessages.isEmpty()) {
return oldList return oldList
}
var myNewList = oldList
newRelevantPrivateMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote ->
val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
if (newNotePair.key == oldRoom) {
hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value)
}
}
}
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
sort(myNewList.toSet()).take(1000)
} }
// Log.d("Time", "${this.javaClass.simpleName} Modified Additive Feed in $elapsed with ${feed.size} objects") var myNewList = oldList
return feed
newRelevantPrivateMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote ->
val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
if (newNotePair.key == oldRoom) {
hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value)
}
}
}
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
return sort(myNewList.toSet()).take(1000)
} }
override fun applyFilter(newItems: Set<Note>): Set<Note> { override fun applyFilter(newItems: Set<Note>): Set<Note> {
@@ -1,6 +1,5 @@
package com.vitorpamplona.amethyst.ui.note package com.vitorpamplona.amethyst.ui.note
import android.util.Log
import androidx.compose.animation.Crossfade import androidx.compose.animation.Crossfade
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background import androidx.compose.foundation.background
@@ -76,7 +75,6 @@ import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue
@OptIn(ExperimentalFoundationApi::class, ExperimentalTime::class) @OptIn(ExperimentalFoundationApi::class, ExperimentalTime::class)
@Composable @Composable
@@ -130,27 +128,21 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, showHi
} }
Column(modifier = columnModifier) { Column(modifier = columnModifier) {
val (value, elapsed) = measureTimedValue { Galeries(multiSetCard, backgroundColor, accountViewModel, nav)
Galeries(multiSetCard, backgroundColor, accountViewModel, nav)
}
Log.d("Rendering Metrics", "All Galeries: ${baseNote.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed - ")
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {
Spacer(modifier = WidthAuthorPictureModifierWithPadding) Spacer(modifier = WidthAuthorPictureModifierWithPadding)
val (value, elapsed) = measureTimedValue { NoteCompose(
NoteCompose( baseNote = baseNote,
baseNote = baseNote, routeForLastRead = null,
routeForLastRead = null, modifier = remember { Modifier.padding(top = 5.dp) },
modifier = remember { Modifier.padding(top = 5.dp) }, isBoostedNote = true,
isBoostedNote = true, showHidden = showHidden,
showHidden = showHidden, parentBackgroundColor = backgroundColor,
parentBackgroundColor = backgroundColor, accountViewModel = accountViewModel,
accountViewModel = accountViewModel, nav = nav
nav = nav )
)
}
Log.d("Rendering Metrics", "Complete: ${baseNote.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
NoteDropDownMenu(baseNote, popupExpanded, accountViewModel) NoteDropDownMenu(baseNote, popupExpanded, accountViewModel)
} }
@@ -168,9 +160,6 @@ private fun Galeries(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
val boostEvents by remember { derivedStateOf { multiSetCard.boostEvents } }
val likeEvents by remember { derivedStateOf { multiSetCard.likeEventsByType } }
val hasZapEvents by remember { derivedStateOf { multiSetCard.zapEvents.isNotEmpty() } } val hasZapEvents by remember { derivedStateOf { multiSetCard.zapEvents.isNotEmpty() } }
val hasBoostEvents by remember { derivedStateOf { multiSetCard.boostEvents.isNotEmpty() } } val hasBoostEvents by remember { derivedStateOf { multiSetCard.boostEvents.isNotEmpty() } }
val hasLikeEvents by remember { derivedStateOf { multiSetCard.likeEvents.isNotEmpty() } } val hasLikeEvents by remember { derivedStateOf { multiSetCard.likeEvents.isNotEmpty() } }
@@ -188,26 +177,17 @@ private fun Galeries(
} }
} }
val (value, elapsed) = measureTimedValue { RenderZapGallery(zapEvents, backgroundColor, nav, accountViewModel)
RenderZapGallery(zapEvents, backgroundColor, nav, accountViewModel)
}
Log.d("Rendering Metrics", "Galeries Zaps: ${multiSetCard.note.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
} }
if (hasBoostEvents) { if (hasBoostEvents) {
val (value, elapsed) = measureTimedValue { RenderBoostGallery(multiSetCard.boostEvents, nav, accountViewModel)
RenderBoostGallery(boostEvents, nav, accountViewModel)
}
Log.d("Rendering Metrics", "Galeries Repost: ${multiSetCard.note.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
} }
if (hasLikeEvents) { if (hasLikeEvents) {
val (value, elapsed) = measureTimedValue { multiSetCard.likeEventsByType.forEach {
likeEvents.forEach { RenderLikeGallery(it.key, it.value, nav, accountViewModel)
RenderLikeGallery(it.key, it.value, nav, accountViewModel)
}
} }
Log.d("Rendering Metrics", "Galeries Like: ${multiSetCard.note.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
} }
} }
@@ -220,7 +220,6 @@ import java.math.BigDecimal
import java.net.URL import java.net.URL
import java.net.URLEncoder import java.net.URLEncoder
import java.util.Locale import java.util.Locale
import kotlin.time.measureTimedValue
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
@@ -961,30 +960,24 @@ fun InnerNoteWithReactions(
) { ) {
if (notBoostedNorQuote) { if (notBoostedNorQuote) {
Column(WidthAuthorPictureModifier) { Column(WidthAuthorPictureModifier) {
val (value, elapsed) = measureTimedValue { AuthorAndRelayInformation(baseNote, accountViewModel, nav)
AuthorAndRelayInformation(baseNote, accountViewModel, nav)
}
Log.d("Rendering Metrics", "Author: ${baseNote.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
} }
Spacer(modifier = DoubleHorzSpacer) Spacer(modifier = DoubleHorzSpacer)
} }
Column(Modifier.fillMaxWidth()) { Column(Modifier.fillMaxWidth()) {
val showSecondRow = baseNote.event !is RepostEvent && baseNote.event !is GenericRepostEvent && !isBoostedNote && !isQuotedNote val showSecondRow = baseNote.event !is RepostEvent && baseNote.event !is GenericRepostEvent && !isBoostedNote && !isQuotedNote
val (value, elapsed) = measureTimedValue { NoteBody(
NoteBody( baseNote = baseNote,
baseNote = baseNote, showAuthorPicture = isQuotedNote,
showAuthorPicture = isQuotedNote, unPackReply = unPackReply,
unPackReply = unPackReply, makeItShort = makeItShort,
makeItShort = makeItShort, canPreview = canPreview,
canPreview = canPreview, showSecondRow = showSecondRow,
showSecondRow = showSecondRow, backgroundColor = backgroundColor,
backgroundColor = backgroundColor, accountViewModel = accountViewModel,
accountViewModel = accountViewModel, nav = nav
nav = nav )
)
}
Log.d("Rendering Metrics", "TextBody: ${baseNote.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
} }
} }
@@ -997,15 +990,12 @@ fun InnerNoteWithReactions(
Spacer(modifier = DoubleVertSpacer) Spacer(modifier = DoubleVertSpacer)
} }
} else { } else {
val (value, elapsed) = measureTimedValue { ReactionsRow(
ReactionsRow( baseNote = baseNote,
baseNote = baseNote, showReactionDetail = notBoostedNorQuote,
showReactionDetail = notBoostedNorQuote, accountViewModel = accountViewModel,
accountViewModel = accountViewModel, nav = nav
nav = nav )
)
}
Log.d("Rendering Metrics", "Reaction: ${baseNote.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
} }
} }
@@ -1,6 +1,5 @@
package com.vitorpamplona.amethyst.ui.screen package com.vitorpamplona.amethyst.ui.screen
import android.util.Log
import androidx.compose.animation.Crossfade import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@@ -18,7 +17,6 @@ import com.vitorpamplona.amethyst.ui.note.ChatroomHeaderCompose
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.FeedPadding import com.vitorpamplona.amethyst.ui.theme.FeedPadding
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue
@Composable @Composable
fun ChatroomListFeedView( fun ChatroomListFeedView(
@@ -96,14 +94,11 @@ private fun FeedLoaded(
key = { index, item -> if (index == 0) index else item.idHex } key = { index, item -> if (index == 0) index else item.idHex }
) { _, item -> ) { _, item ->
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {
val (value, elapsed) = measureTimedValue { ChatroomHeaderCompose(
ChatroomHeaderCompose( item,
item, accountViewModel = accountViewModel,
accountViewModel = accountViewModel, nav = nav
nav = nav )
)
}
Log.d("Rendering Metrics", "Chat Header Complete: ${item.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
} }
} }
} }
@@ -1,6 +1,5 @@
package com.vitorpamplona.amethyst.ui.screen package com.vitorpamplona.amethyst.ui.screen
import android.util.Log
import androidx.compose.animation.Crossfade import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
@@ -38,7 +37,6 @@ import com.vitorpamplona.amethyst.ui.note.NoteCompose
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.FeedPadding import com.vitorpamplona.amethyst.ui.theme.FeedPadding
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue
@Composable @Composable
fun RefresheableFeedView( fun RefresheableFeedView(
@@ -224,27 +222,23 @@ private fun FeedLoaded(
state = listState state = listState
) { ) {
itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item -> itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item ->
val (value, elapsed) = measureTimedValue { val defaultModifier = remember {
val defaultModifier = remember { Modifier
Modifier .fillMaxWidth()
.fillMaxWidth() .animateItemPlacement()
.animateItemPlacement()
}
Row(defaultModifier) {
NoteCompose(
item,
routeForLastRead = routeForLastRead,
modifier = Modifier,
isBoostedNote = false,
showHidden = state.showHidden.value,
accountViewModel = accountViewModel,
nav = nav
)
}
} }
Log.d("Rendering Metrics", "Complete: ${item.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed") Row(defaultModifier) {
NoteCompose(
item,
routeForLastRead = routeForLastRead,
modifier = Modifier,
isBoostedNote = false,
showHidden = state.showHidden.value,
accountViewModel = accountViewModel,
nav = nav
)
}
} }
} }
} }