perf: convert 194 interpolated Log.d() calls to lambda overloads

Defers string construction until after the level check, avoiding
allocation when debug logging is filtered in release/benchmark builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
davotoula
2026-03-28 16:21:39 +01:00
parent 541b197a64
commit 3b81731771
78 changed files with 205 additions and 214 deletions
@@ -124,7 +124,7 @@ class EphemeralChatListState(
scope.launch(Dispatchers.IO) {
Log.d("AccountRegisterObservers", "EphemeralChatList Collector Start")
getEphemeralChatListFlow().collect { noteState ->
Log.d("AccountRegisterObservers", "EphemeralChatList List for ${signer.pubKey}")
Log.d("AccountRegisterObservers") { "EphemeralChatList List for ${signer.pubKey}" }
(noteState.note.event as? EphemeralChatListEvent)?.let {
settings.updateEphemeralChatListTo(it)
}
@@ -161,7 +161,7 @@ class Kind3FollowListState(
init {
settings.backupContactList?.let {
Log.d("AccountRegisterObservers", "Loading saved ${it.tags.size} contacts")
Log.d("AccountRegisterObservers") { "Loading saved ${it.tags.size} contacts" }
@OptIn(DelicateCoroutinesApi::class)
scope.launch(Dispatchers.IO) { cache.justConsumeMyOwnEvent(it) }
@@ -171,7 +171,7 @@ class Kind3FollowListState(
scope.launch(Dispatchers.IO) {
Log.d("AccountRegisterObservers", "Kind 3 Collector Start")
getFollowListFlow().collect {
Log.d("AccountRegisterObservers", "Updating Kind 3 ${signer.pubKey}")
Log.d("AccountRegisterObservers") { "Updating Kind 3 ${signer.pubKey}" }
(it.note.event as? ContactListEvent)?.let {
settings.updateContactListTo(it)
}
@@ -129,7 +129,7 @@ class PublicChatListState(
init {
settings.channelList()?.let { event ->
Log.d("AccountRegisterObservers", "Loading saved channel list ${event.toJson()}")
Log.d("AccountRegisterObservers") { "Loading saved channel list ${event.toJson()}" }
@OptIn(DelicateCoroutinesApi::class)
scope.launch(Dispatchers.IO) {
cache.justConsumeMyOwnEvent(event)
@@ -139,7 +139,7 @@ class PublicChatListState(
scope.launch(Dispatchers.IO) {
Log.d("AccountRegisterObservers", "Channel List Collector Start")
getChannelListFlow().collect {
Log.d("AccountRegisterObservers", "Channel List for ${signer.pubKey}")
Log.d("AccountRegisterObservers") { "Channel List for ${signer.pubKey}" }
(it.note.event as? ChannelListEvent)?.let {
settings.updateChannelListTo(it)
}
@@ -142,7 +142,7 @@ class Nip65RelayListState(
init {
settings.backupNIP65RelayList?.let {
Log.d("AccountRegisterObservers", "Loading saved nip65 relay list ${it.toJson()}")
Log.d("AccountRegisterObservers") { "Loading saved nip65 relay list ${it.toJson()}" }
@OptIn(DelicateCoroutinesApi::class)
scope.launch(Dispatchers.IO) { cache.justConsumeMyOwnEvent(it) }
}
@@ -150,7 +150,7 @@ class Nip65RelayListState(
scope.launch(Dispatchers.IO) {
Log.d("AccountRegisterObservers", "NIP-65 Relay List Collector Start")
getNIP65RelayListFlow().collect {
Log.d("AccountRegisterObservers", "Updating NIP-65 List for ${signer.pubKey}")
Log.d("AccountRegisterObservers") { "Updating NIP-65 List for ${signer.pubKey}" }
(it.note.event as? AdvertisedRelayListEvent)?.let {
settings.updateNIP65RelayList(it)
}
@@ -39,7 +39,7 @@ inline fun <T> logTime(
if (isDebug) {
val (result, elapsed) = measureTimedValue(block)
if (elapsed.inWholeMilliseconds > minToReportMs) {
Log.d("DEBUG-TIME", "${elapsed.toString(DurationUnit.MILLISECONDS, 3).padStart(12)}: $debugMessage")
Log.d("DEBUG-TIME") { "${elapsed.toString(DurationUnit.MILLISECONDS, 3).padStart(12)}: $debugMessage" }
}
result
} else {
@@ -54,7 +54,7 @@ inline fun <T> logTime(
if (isDebug) {
val (result, elapsed) = measureTimedValue(block)
if (elapsed.inWholeMilliseconds > minToReportMs) {
Log.d("DEBUG-TIME", "${elapsed.toString(DurationUnit.MILLISECONDS, 3).padStart(12)}: ${debugMessage(result)}")
Log.d("DEBUG-TIME") { "${elapsed.toString(DurationUnit.MILLISECONDS, 3).padStart(12)}: ${debugMessage(result)}" }
}
result
} else {
@@ -49,24 +49,24 @@ abstract class FeedViewModel(
override fun invalidateData(ignoreIfDoing: Boolean) = feedState.invalidateData(ignoreIfDoing)
init {
Log.d("Init", "Starting new Model: ${this::class.simpleName}")
Log.d("Init") { "Starting new Model: ${this::class.simpleName}" }
viewModelScope.launch(Dispatchers.IO) {
cacheProvider.getEventStream().newEventBundles.collect { newNotes ->
Log.d("Rendering Metrics", "Update feeds: ${this@FeedViewModel::class.simpleName} with ${newNotes.size}")
Log.d("Rendering Metrics") { "Update feeds: ${this@FeedViewModel::class.simpleName} with ${newNotes.size}" }
feedState.updateFeedWith(newNotes)
}
}
viewModelScope.launch(Dispatchers.IO) {
cacheProvider.getEventStream().deletedEventBundles.collect { newNotes ->
Log.d("Rendering Metrics", "Delete from feeds: ${this@FeedViewModel::class.simpleName} with ${newNotes.size}")
Log.d("Rendering Metrics") { "Delete from feeds: ${this@FeedViewModel::class.simpleName} with ${newNotes.size}" }
feedState.deleteFromFeed(newNotes)
}
}
}
override fun onCleared() {
Log.d("Init", "OnCleared: ${this::class.simpleName}")
Log.d("Init") { "OnCleared: ${this::class.simpleName}" }
super.onCleared()
}
}
@@ -46,14 +46,14 @@ abstract class ListChangeFeedViewModel(
override fun invalidateData(ignoreIfDoing: Boolean) = feedState.invalidateData(ignoreIfDoing)
init {
Log.d("Init", "Starting new Model: ${this::class.simpleName}")
Log.d("Init") { "Starting new Model: ${this::class.simpleName}" }
// Trigger initial load so empty rooms show Empty instead of Loading
viewModelScope.launch(Dispatchers.IO) {
feedState.invalidateData(ignoreIfDoing = false)
}
viewModelScope.launch(Dispatchers.IO) {
localFilter.changesFlow().collect {
Log.d("Init", "Collecting changes to: ${this@ListChangeFeedViewModel::class.simpleName}")
Log.d("Init") { "Collecting changes to: ${this@ListChangeFeedViewModel::class.simpleName}" }
when (it) {
is ListChange.Addition -> feedState.updateFeedWith(setOf(it.item))
is ListChange.Deletion -> feedState.deleteFromFeed(setOf(it.item))