Removes the memory counter methods because they are not the best way to measure the size in memory of these objects, since we intern strings all the time.

This commit is contained in:
Vitor Pamplona
2026-01-14 16:49:11 -05:00
parent 3d0b0c01b9
commit 92d4654b20
39 changed files with 20 additions and 263 deletions
@@ -26,8 +26,11 @@ import android.content.pm.ApplicationInfo
import android.os.Debug
import androidx.core.content.getSystemService
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizedUrls
import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
import kotlin.time.DurationUnit
import kotlin.time.measureTimedValue
@@ -228,3 +231,12 @@ inline fun debug(
Log.d(tag, debugMessage())
}
}
fun Event.countMemory(): Int =
7 * pointerSizeInBytes + // 7 fields, 4 bytes each reference (32bit)
12 + // createdAt + kind
id.bytesUsedInMemory() +
pubKey.bytesUsedInMemory() +
tags.sumOf { pointerSizeInBytes + it.sumOf { pointerSizeInBytes + it.bytesUsedInMemory() } } +
content.bytesUsedInMemory() +
sig.bytesUsedInMemory()
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.EventMessage
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
/**
* Listens to NostrClient's onNotify messages from the relay
@@ -47,7 +48,7 @@ class RelaySpeedLogger(
msg: Message,
) {
if (msg is EventMessage) {
current.increment(msg.event.kind, msg.subId, relay.url, msg.event.countMemory())
current.increment(msg.event.kind, msg.subId, relay.url, msgStr.bytesUsedInMemory())
}
}
}