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 android.os.Debug
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import com.vitorpamplona.amethyst.model.LocalCache 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.nip01Core.relay.normalizer.normalizedUrls
import com.vitorpamplona.quartz.utils.Log 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.DurationUnit
import kotlin.time.measureTimedValue import kotlin.time.measureTimedValue
@@ -228,3 +231,12 @@ inline fun debug(
Log.d(tag, debugMessage()) 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.EventMessage
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
/** /**
* Listens to NostrClient's onNotify messages from the relay * Listens to NostrClient's onNotify messages from the relay
@@ -47,7 +48,7 @@ class RelaySpeedLogger(
msg: Message, msg: Message,
) { ) {
if (msg is EventMessage) { 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())
} }
} }
} }
@@ -23,8 +23,6 @@ package com.vitorpamplona.quartz.nip01Core.core
import android.os.Parcel import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Stable @Stable
actual data class Address actual constructor( actual data class Address actual constructor(
@@ -35,12 +33,6 @@ actual data class Address actual constructor(
Parcelable { Parcelable {
actual fun toValue() = assemble(kind, pubKeyHex, dTag) actual fun toValue() = assemble(kind, pubKeyHex, dTag)
actual fun countMemory(): Int =
3 * pointerSizeInBytes +
8 + // kind
pubKeyHex.bytesUsedInMemory() +
dTag.bytesUsedInMemory()
actual override fun compareTo(other: Address): Int { actual override fun compareTo(other: Address): Int {
val kindComparison = kind.compareTo(other.kind) val kindComparison = kind.compareTo(other.kind)
return if (kindComparison == 0) { return if (kindComparison == 0) {
@@ -27,9 +27,7 @@ import com.vitorpamplona.quartz.nip01Core.core.has
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class RootSceneTag( data class RootSceneTag(
@@ -48,13 +46,6 @@ data class RootSceneTag(
this.relay = relayHint this.relay = relayHint
} }
fun countMemory(): Int =
5 * pointerSizeInBytes + // 7 fields, 4 bytes each reference (32bit)
8 + // kind
pubKeyHex.bytesUsedInMemory() +
dTag.bytesUsedInMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0)
fun toTag() = assembleATagId(kind, pubKeyHex, dTag) fun toTag() = assembleATagId(kind, pubKeyHex, dTag)
fun toTagArray() = assemble(kind, pubKeyHex, dTag, relay) fun toTagArray() = assemble(kind, pubKeyHex, dTag, relay)
@@ -33,8 +33,6 @@ expect class Address(
fun toValue(): String fun toValue(): String
fun countMemory(): Int
companion object { companion object {
fun assemble( fun assemble(
kind: Int, kind: Int,
@@ -24,8 +24,6 @@ import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
open class Event( open class Event(
@@ -44,15 +42,6 @@ open class Event(
*/ */
open fun isContentEncoded() = false open fun isContentEncoded() = false
open fun 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()
fun toJson(): String = OptimizedJsonMapper.toJson(this) fun toJson(): String = OptimizedJsonMapper.toJson(this)
companion object { companion object {
@@ -24,8 +24,6 @@ import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class EventHintBundle<T : Event>( data class EventHintBundle<T : Event>(
@@ -39,10 +37,5 @@ data class EventHintBundle<T : Event>(
this.authorHomeRelay = authorHomeRelay this.authorHomeRelay = authorHomeRelay
} }
fun countMemory(): Int =
2 * pointerSizeInBytes + // 2 fields, 4 bytes each reference (32bit)
event.countMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0)
fun toNEvent(): String = NEvent.create(event.id, event.pubKey, event.kind, relay) fun toNEvent(): String = NEvent.create(event.id, event.pubKey, event.kind, relay)
} }
@@ -32,9 +32,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip01Core.tags.dTag.dTag import com.vitorpamplona.quartz.nip01Core.tags.dTag.dTag
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class ATag( data class ATag(
@@ -45,13 +43,6 @@ data class ATag(
) { ) {
constructor(address: Address, relayHint: NormalizedRelayUrl? = null) : this(address.kind, address.pubKeyHex, address.dTag, relayHint) constructor(address: Address, relayHint: NormalizedRelayUrl? = null) : this(address.kind, address.pubKeyHex, address.dTag, relayHint)
fun countMemory(): Int =
5 * pointerSizeInBytes + // 7 fields, 4 bytes each reference (32bit)
8 + // kind
pubKeyHex.bytesUsedInMemory() +
dTag.bytesUsedInMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0)
fun toTag() = AddressSerializer.assemble(kind, pubKeyHex, dTag) fun toTag() = AddressSerializer.assemble(kind, pubKeyHex, dTag)
fun toATagArray() = assemble(toTag(), relay) fun toATagArray() = assemble(toTag(), relay)
@@ -20,14 +20,9 @@
*/ */
package com.vitorpamplona.quartz.nip01Core.tags.dTag package com.vitorpamplona.quartz.nip01Core.tags.dTag
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class DTag( class DTag(
val dId: String, val dId: String,
) { ) {
fun countMemory(): Int = 1 * pointerSizeInBytes + dId.bytesUsedInMemory()
fun toTagArray() = assemble(dId) fun toTagArray() = assemble(dId)
companion object { companion object {
@@ -30,9 +30,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class ETag( data class ETag(
@@ -46,12 +44,6 @@ data class ETag(
this.author = authorPubKeyHex this.author = authorPubKeyHex
} }
fun countMemory(): Int =
3 * pointerSizeInBytes + // 3 fields, 4 bytes each reference (32bit)
eventId.bytesUsedInMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0) +
(author?.bytesUsedInMemory() ?: 0)
fun toNEvent(): String = NEvent.create(eventId, author, null, relay) fun toNEvent(): String = NEvent.create(eventId, author, null, relay)
override fun toTagArray() = assemble(eventId, relay, author) override fun toTagArray() = assemble(eventId, relay, author)
@@ -33,20 +33,13 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile
import com.vitorpamplona.quartz.nip19Bech32.toNpub import com.vitorpamplona.quartz.nip19Bech32.toNpub
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class PTag( data class PTag(
override val pubKey: HexKey, override val pubKey: HexKey,
override val relayHint: NormalizedRelayUrl? = null, override val relayHint: NormalizedRelayUrl? = null,
) : PubKeyReferenceTag { ) : PubKeyReferenceTag {
fun countMemory(): Int =
2 * pointerSizeInBytes + // 2 fields, 4 bytes each reference (32bit)
pubKey.bytesUsedInMemory() +
(relayHint?.url?.bytesUsedInMemory() ?: 0)
fun toNProfile(): String = NProfile.create(pubKey, relayHint?.let { listOf(it) } ?: emptyList()) fun toNProfile(): String = NProfile.create(pubKey, relayHint?.let { listOf(it) } ?: emptyList())
fun toNPub(): String = pubKey.hexToByteArray().toNpub() fun toNPub(): String = pubKey.hexToByteArray().toNpub()
@@ -31,9 +31,7 @@ import com.vitorpamplona.quartz.nip19Bech32.decodePublicKey
import com.vitorpamplona.quartz.utils.Hex import com.vitorpamplona.quartz.utils.Hex
import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class ContactTag( data class ContactTag(
@@ -51,12 +49,6 @@ data class ContactTag(
this.petname = petname this.petname = petname
} }
fun countMemory(): Int =
3 * pointerSizeInBytes +
pubKey.bytesUsedInMemory() +
(relayUri?.url?.bytesUsedInMemory() ?: 0) +
(petname?.bytesUsedInMemory() ?: 0)
fun toTagArray() = assemble(pubKey, relayUri, petname) fun toTagArray() = assemble(pubKey, relayUri, petname)
companion object { companion object {
@@ -22,16 +22,12 @@ package com.vitorpamplona.quartz.nip13Pow.tags
import com.vitorpamplona.quartz.nip01Core.core.has import com.vitorpamplona.quartz.nip01Core.core.has
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class PoWTag( class PoWTag(
val nonce: String, val nonce: String,
val commitment: Int?, val commitment: Int?,
) { ) {
fun countMemory(): Int = 2 * pointerSizeInBytes + nonce.bytesUsedInMemory() + (commitment?.bytesUsedInMemory() ?: 0)
fun toTagArray() = assemble(nonce, commitment) fun toTagArray() = assemble(nonce, commitment)
companion object { companion object {
@@ -27,9 +27,7 @@ import com.vitorpamplona.quartz.nip01Core.core.has
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class QAddressableTag( data class QAddressableTag(
@@ -53,11 +51,6 @@ data class QAddressableTag(
this.relay = relayHint this.relay = relayHint
} }
fun countMemory(): Int =
2 * pointerSizeInBytes +
address.countMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0)
override fun toTagArray() = assemble(address, relay) override fun toTagArray() = assemble(address, relay)
companion object { companion object {
@@ -28,9 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class QEventTag( data class QEventTag(
@@ -44,12 +42,6 @@ data class QEventTag(
this.author = authorPubKeyHex this.author = authorPubKeyHex
} }
fun countMemory(): Int =
3 * pointerSizeInBytes + // 3 fields, 4 bytes each reference (32bit)
eventId.bytesUsedInMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0) +
(author?.bytesUsedInMemory() ?: 0)
override fun toTagArray() = assemble(eventId, relay, author) override fun toTagArray() = assemble(eventId, relay, author)
companion object { companion object {
@@ -28,9 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
class ChannelTag( class ChannelTag(
@@ -38,12 +36,6 @@ class ChannelTag(
val relay: NormalizedRelayUrl? = null, val relay: NormalizedRelayUrl? = null,
val author: HexKey? = null, val author: HexKey? = null,
) { ) {
fun countMemory(): Int =
3 * pointerSizeInBytes + // 3 fields, 4 bytes each reference (32bit)
eventId.bytesUsedInMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0) +
(author?.bytesUsedInMemory() ?: 0)
fun toNEvent(): String = NEvent.create(eventId, author, null, relay) fun toNEvent(): String = NEvent.create(eventId, author, null, relay)
fun toTagArray() = assemble(eventId, relay, author) fun toTagArray() = assemble(eventId, relay, author)
@@ -22,6 +22,4 @@ package com.vitorpamplona.quartz.nip46RemoteSigner
import com.vitorpamplona.quartz.nip01Core.core.OptimizedSerializable import com.vitorpamplona.quartz.nip01Core.core.OptimizedSerializable
abstract class BunkerMessage : OptimizedSerializable { abstract class BunkerMessage : OptimizedSerializable
abstract fun countMemory(): Int
}
@@ -20,17 +20,8 @@
*/ */
package com.vitorpamplona.quartz.nip46RemoteSigner package com.vitorpamplona.quartz.nip46RemoteSigner
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
open class BunkerRequest( open class BunkerRequest(
val id: String, val id: String,
val method: String, val method: String,
val params: Array<String> = emptyArray(), val params: Array<String> = emptyArray(),
) : BunkerMessage() { ) : BunkerMessage()
override fun countMemory(): Int =
3 * pointerSizeInBytes + // 3 fields, 4 bytes each reference (32bit)
id.bytesUsedInMemory() +
method.bytesUsedInMemory() +
params.sumOf { pointerSizeInBytes + it.bytesUsedInMemory() }
}
@@ -20,17 +20,8 @@
*/ */
package com.vitorpamplona.quartz.nip46RemoteSigner package com.vitorpamplona.quartz.nip46RemoteSigner
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
open class BunkerResponse( open class BunkerResponse(
val id: String, val id: String,
val result: String?, val result: String?,
val error: String?, val error: String?,
) : BunkerMessage() { ) : BunkerMessage()
override fun countMemory(): Int =
3 * pointerSizeInBytes + // 3 fields, 4 bytes each reference (32bit)
id.bytesUsedInMemory() +
(result?.bytesUsedInMemory() ?: 0) +
(error?.bytesUsedInMemory() ?: 0)
}
@@ -21,15 +21,11 @@
package com.vitorpamplona.quartz.nip47WalletConnect package com.vitorpamplona.quartz.nip47WalletConnect
import com.vitorpamplona.quartz.nip01Core.core.OptimizedSerializable import com.vitorpamplona.quartz.nip01Core.core.OptimizedSerializable
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
// RESPONSE OBJECTS // RESPONSE OBJECTS
abstract class Response( abstract class Response(
val resultType: String, val resultType: String,
) : OptimizedSerializable { ) : OptimizedSerializable
abstract fun countMemory(): Int
}
// PayInvoice Call // PayInvoice Call
@@ -38,11 +34,7 @@ class PayInvoiceSuccessResponse(
) : Response("pay_invoice") { ) : Response("pay_invoice") {
class PayInvoiceResultParams( class PayInvoiceResultParams(
val preimage: String? = null, val preimage: String? = null,
) { )
fun countMemory(): Int = pointerSizeInBytes + (preimage?.bytesUsedInMemory() ?: 0)
}
override fun countMemory(): Int = pointerSizeInBytes + (result?.countMemory() ?: 0)
} }
class PayInvoiceErrorResponse( class PayInvoiceErrorResponse(
@@ -51,11 +43,7 @@ class PayInvoiceErrorResponse(
class PayInvoiceErrorParams( class PayInvoiceErrorParams(
val code: ErrorType? = null, val code: ErrorType? = null,
val message: String? = null, val message: String? = null,
) { )
fun countMemory(): Int = pointerSizeInBytes + pointerSizeInBytes + (message?.bytesUsedInMemory() ?: 0)
}
override fun countMemory(): Int = pointerSizeInBytes + (error?.countMemory() ?: 0)
enum class ErrorType { enum class ErrorType {
RATE_LIMITED, RATE_LIMITED,
@@ -22,17 +22,13 @@ package com.vitorpamplona.quartz.nip48ProxyTags
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.core.has import com.vitorpamplona.quartz.nip01Core.core.has
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
data class ProxyTag( data class ProxyTag(
val id: String, val id: String,
val protocol: String, val protocol: String,
) { ) {
fun countMemory(): Int = 2 * pointerSizeInBytes + id.bytesUsedInMemory() + protocol.bytesUsedInMemory()
fun toTagArray() = assemble(id, protocol) fun toTagArray() = assemble(id, protocol)
companion object { companion object {
@@ -27,16 +27,12 @@ import com.vitorpamplona.quartz.nip01Core.hints.types.AddressHint
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class AddressBookmark( class AddressBookmark(
val address: Address, val address: Address,
val relayHint: NormalizedRelayUrl? = null, val relayHint: NormalizedRelayUrl? = null,
) : BookmarkIdTag { ) : BookmarkIdTag {
fun countMemory(): Int = 2 * pointerSizeInBytes + address.countMemory() + (relayHint?.url?.bytesUsedInMemory() ?: 0)
fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag) fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag)
override fun toTagArray() = assemble(address, relayHint) override fun toTagArray() = assemble(address, relayHint)
@@ -28,9 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
class EventBookmark( class EventBookmark(
@@ -38,12 +36,6 @@ class EventBookmark(
val relay: NormalizedRelayUrl? = null, val relay: NormalizedRelayUrl? = null,
val author: HexKey? = null, val author: HexKey? = null,
) : BookmarkIdTag { ) : BookmarkIdTag {
fun countMemory(): Int =
3 * pointerSizeInBytes + // 3 fields, 4 bytes each reference (32bit)
eventId.bytesUsedInMemory() +
(relay?.url?.bytesUsedInMemory() ?: 0) +
(author?.bytesUsedInMemory() ?: 0)
fun toNEvent(): String = NEvent.create(eventId, author, null, relay) fun toNEvent(): String = NEvent.create(eventId, author, null, relay)
override fun toTagArray() = assemble(eventId, relay, author) override fun toTagArray() = assemble(eventId, relay, author)
@@ -30,19 +30,12 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile
import com.vitorpamplona.quartz.nip19Bech32.toNpub import com.vitorpamplona.quartz.nip19Bech32.toNpub
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class UserTag( class UserTag(
val pubKey: HexKey, val pubKey: HexKey,
val relayHint: NormalizedRelayUrl? = null, val relayHint: NormalizedRelayUrl? = null,
) : MuteTag { ) : MuteTag {
fun countMemory(): Int =
2 * pointerSizeInBytes + // 2 fields, 4 bytes each reference (32bit)
pubKey.bytesUsedInMemory() +
(relayHint?.url?.bytesUsedInMemory() ?: 0)
fun toNProfile(): String = NProfile.create(pubKey, relayHint?.let { listOf(it) } ?: emptyList()) fun toNProfile(): String = NProfile.create(pubKey, relayHint?.let { listOf(it) } ?: emptyList())
fun toNPub(): String = pubKey.hexToByteArray().toNpub() fun toNPub(): String = pubKey.hexToByteArray().toNpub()
@@ -23,18 +23,12 @@ package com.vitorpamplona.quartz.nip51Lists.muteList.tags
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.core.has import com.vitorpamplona.quartz.nip01Core.core.has
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
class WordTag( class WordTag(
val word: String, val word: String,
) : MuteTag { ) : MuteTag {
fun countMemory(): Int =
1 * pointerSizeInBytes + // 1 fields, 4 bytes each reference (32bit)
word.bytesUsedInMemory()
override fun toTagArray() = assemble(word) override fun toTagArray() = assemble(word)
override fun toTagIdOnly() = assemble(word) override fun toTagIdOnly() = assemble(word)
@@ -27,16 +27,12 @@ import com.vitorpamplona.quartz.nip01Core.hints.types.AddressHint
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class MeetingSpaceTag( class MeetingSpaceTag(
val address: Address, val address: Address,
val relayHint: NormalizedRelayUrl? = null, val relayHint: NormalizedRelayUrl? = null,
) { ) {
fun countMemory(): Int = 2 * pointerSizeInBytes + address.countMemory() + (relayHint?.url?.bytesUsedInMemory() ?: 0)
fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag) fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag)
fun toTagArray() = assemble(address, relayHint) fun toTagArray() = assemble(address, relayHint)
@@ -27,16 +27,12 @@ import com.vitorpamplona.quartz.nip01Core.hints.types.AddressHint
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class MeetingRoomTag( class MeetingRoomTag(
val address: Address, val address: Address,
val relayHint: NormalizedRelayUrl? = null, val relayHint: NormalizedRelayUrl? = null,
) { ) {
fun countMemory(): Int = 2 * pointerSizeInBytes + address.countMemory() + (relayHint?.url?.bytesUsedInMemory() ?: 0)
fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag) fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag)
fun toTagArray() = assemble(address, relayHint) fun toTagArray() = assemble(address, relayHint)
@@ -32,7 +32,6 @@ import com.vitorpamplona.quartz.nip01Core.tags.aTag.ATag
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
class LnZapEvent( class LnZapEvent(
@@ -74,11 +73,6 @@ class LnZapEvent(
} }
} }
override fun countMemory(): Int =
super.countMemory() +
pointerSizeInBytes + (zapRequest?.countMemory() ?: 0) + // rough calculation
pointerSizeInBytes + 36 // bigdecimal size
override fun containedPost(): LnZapRequestEvent? = override fun containedPost(): LnZapRequestEvent? =
try { try {
description()?.ifBlank { null }?.let { fromJson(it) } as? LnZapRequestEvent description()?.ifBlank { null }?.let { fromJson(it) } as? LnZapRequestEvent
@@ -20,14 +20,9 @@
*/ */
package com.vitorpamplona.quartz.nip57Zaps.zapraiser package com.vitorpamplona.quartz.nip57Zaps.zapraiser
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class ZapRaiserTag( class ZapRaiserTag(
val amountInSats: Long, val amountInSats: Long,
) { ) {
fun countMemory(): Int = 1 * pointerSizeInBytes + amountInSats.bytesUsedInMemory()
fun toTagArray() = assemble(amountInSats) fun toTagArray() = assemble(amountInSats)
companion object { companion object {
@@ -30,8 +30,6 @@ import com.vitorpamplona.quartz.nip59Giftwrap.WrappedEvent
import com.vitorpamplona.quartz.nip59Giftwrap.rumors.Rumor import com.vitorpamplona.quartz.nip59Giftwrap.rumors.Rumor
import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
class SealedRumorEvent( class SealedRumorEvent(
@@ -46,10 +44,6 @@ class SealedRumorEvent(
@kotlin.jvm.Transient @kotlin.jvm.Transient
var innerEventId: HexKey? = null var innerEventId: HexKey? = null
override fun countMemory(): Int =
super.countMemory() +
pointerSizeInBytes + (innerEventId?.bytesUsedInMemory() ?: 0)
fun copyNoContent(): SealedRumorEvent { fun copyNoContent(): SealedRumorEvent {
val copy = val copy =
SealedRumorEvent( SealedRumorEvent(
@@ -34,8 +34,6 @@ import com.vitorpamplona.quartz.nip59Giftwrap.HostStub
import com.vitorpamplona.quartz.nip59Giftwrap.WrappedEvent import com.vitorpamplona.quartz.nip59Giftwrap.WrappedEvent
import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
class GiftWrapEvent( class GiftWrapEvent(
@@ -50,10 +48,6 @@ class GiftWrapEvent(
@kotlin.jvm.Transient @kotlin.jvm.Transient
var innerEventId: HexKey? = null var innerEventId: HexKey? = null
override fun countMemory(): Int =
super.countMemory() +
pointerSizeInBytes + (innerEventId?.bytesUsedInMemory() ?: 0)
fun copyNoContent(): GiftWrapEvent { fun copyNoContent(): GiftWrapEvent {
val copy = val copy =
GiftWrapEvent( GiftWrapEvent(
@@ -23,19 +23,12 @@ package com.vitorpamplona.quartz.nip71Video.tags
import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.has import com.vitorpamplona.quartz.nip01Core.core.has
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
data class TextTrackTag( data class TextTrackTag(
val eventId: HexKey, val eventId: HexKey,
var relay: String? = null, var relay: String? = null,
) { ) {
fun countMemory(): Int =
2 * pointerSizeInBytes + // 3 fields, 4 bytes each reference (32bit)
eventId.bytesUsedInMemory() +
(relay?.bytesUsedInMemory() ?: 0)
fun toTagArray() = arrayOfNotNull(TAG_NAME, eventId, relay) fun toTagArray() = arrayOfNotNull(TAG_NAME, eventId, relay)
companion object { companion object {
@@ -28,16 +28,12 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip72ModCommunities.definition.CommunityDefinitionEvent import com.vitorpamplona.quartz.nip72ModCommunities.definition.CommunityDefinitionEvent
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class ApprovedAddressTag( class ApprovedAddressTag(
val address: Address, val address: Address,
val relayHint: NormalizedRelayUrl? = null, val relayHint: NormalizedRelayUrl? = null,
) { ) {
fun countMemory(): Int = 2 * pointerSizeInBytes + address.countMemory() + (relayHint?.url?.bytesUsedInMemory() ?: 0)
fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag) fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag)
fun toTagArray() = assemble(address, relayHint) fun toTagArray() = assemble(address, relayHint)
@@ -28,16 +28,12 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip72ModCommunities.definition.CommunityDefinitionEvent import com.vitorpamplona.quartz.nip72ModCommunities.definition.CommunityDefinitionEvent
import com.vitorpamplona.quartz.utils.arrayOfNotNull import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.ensure import com.vitorpamplona.quartz.utils.ensure
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
class CommunityTag( class CommunityTag(
val address: Address, val address: Address,
val relayHint: NormalizedRelayUrl? = null, val relayHint: NormalizedRelayUrl? = null,
) { ) {
fun countMemory(): Int = 2 * pointerSizeInBytes + address.countMemory() + (relayHint?.url?.bytesUsedInMemory() ?: 0)
fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag) fun toTag() = Address.assemble(address.kind, address.pubKeyHex, address.dTag)
fun toTagArray() = assemble(address, relayHint) fun toTagArray() = assemble(address, relayHint)
@@ -51,8 +51,6 @@ class AppDefinitionEvent(
sig: HexKey, sig: HexKey,
) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig), ) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig),
PublishedAtProvider { PublishedAtProvider {
override fun countMemory(): Int = super.countMemory() + (cachedMetadata?.countMemory() ?: 8)
@kotlinx.serialization.Transient @kotlinx.serialization.Transient
@kotlin.jvm.Transient @kotlin.jvm.Transient
private var cachedMetadata: AppMetadata? = null private var cachedMetadata: AppMetadata? = null
@@ -22,8 +22,6 @@ package com.vitorpamplona.quartz.nip89AppHandlers.definition
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import com.vitorpamplona.quartz.nip01Core.core.JsonMapper import com.vitorpamplona.quartz.nip01Core.core.JsonMapper
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@@ -52,26 +50,6 @@ class AppMetadata {
var lud06: String? = null var lud06: String? = null
var lud16: String? = null var lud16: String? = null
fun countMemory(): Int =
20 * pointerSizeInBytes + // 20 fields, 4 bytes for each reference
(name?.bytesUsedInMemory() ?: 0) +
(username?.bytesUsedInMemory() ?: 0) +
(displayName?.bytesUsedInMemory() ?: 0) +
(picture?.bytesUsedInMemory() ?: 0) +
(banner?.bytesUsedInMemory() ?: 0) +
(image?.bytesUsedInMemory() ?: 0) +
(website?.bytesUsedInMemory() ?: 0) +
(about?.bytesUsedInMemory() ?: 0) +
(subscription?.bytesUsedInMemory() ?: 0) +
(acceptsNutZaps?.bytesUsedInMemory() ?: 0) +
(supportsEncryption?.bytesUsedInMemory() ?: 0) +
(personalized?.bytesUsedInMemory() ?: 0) + // A Boolean has 8 bytes of header, plus 1 byte of payload, for a total of 9 bytes of information. The JVM then rounds it up to the next multiple of 8. so the one instance of java.lang.Boolean takes up 16 bytes of memory.
(amount?.bytesUsedInMemory() ?: 0) +
(nip05?.bytesUsedInMemory() ?: 0) +
(domain?.bytesUsedInMemory() ?: 0) +
(lud06?.bytesUsedInMemory() ?: 0) +
(lud16?.bytesUsedInMemory() ?: 0)
fun anyName(): String? = displayName ?: name ?: username fun anyName(): String? = displayName ?: name ?: username
fun anyNameStartsWith(prefix: String): Boolean = fun anyNameStartsWith(prefix: String): Boolean =
@@ -28,8 +28,6 @@ import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip31Alts.AltTag import com.vitorpamplona.quartz.nip31Alts.AltTag
import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@Immutable @Immutable
class NIP90ContentDiscoveryResponseEvent( class NIP90ContentDiscoveryResponseEvent(
@@ -44,10 +42,6 @@ class NIP90ContentDiscoveryResponseEvent(
@kotlin.jvm.Transient @kotlin.jvm.Transient
var events: List<HexKey>? = null var events: List<HexKey>? = null
override fun countMemory(): Int =
super.countMemory() +
pointerSizeInBytes + (events?.sumOf { it.bytesUsedInMemory() } ?: 0)
fun innerTags(): List<HexKey> { fun innerTags(): List<HexKey> {
if (content.isEmpty()) { if (content.isEmpty()) {
return listOf() return listOf()
@@ -20,9 +20,6 @@
*/ */
package com.vitorpamplona.quartz.nip01Core.core package com.vitorpamplona.quartz.nip01Core.core
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
actual data class Address actual constructor( actual data class Address actual constructor(
actual val kind: Kind, actual val kind: Kind,
actual val pubKeyHex: HexKey, actual val pubKeyHex: HexKey,
@@ -30,12 +27,6 @@ actual data class Address actual constructor(
) : Comparable<Address> { ) : Comparable<Address> {
actual fun toValue() = assemble(kind, pubKeyHex, dTag) actual fun toValue() = assemble(kind, pubKeyHex, dTag)
actual fun countMemory(): Int =
3 * pointerSizeInBytes +
8 + // kind
pubKeyHex.bytesUsedInMemory() +
dTag.bytesUsedInMemory()
actual override fun compareTo(other: Address): Int { actual override fun compareTo(other: Address): Int {
val result = kind.compareTo(other.kind) val result = kind.compareTo(other.kind)
return if (result == 0) { return if (result == 0) {
@@ -20,9 +20,6 @@
*/ */
package com.vitorpamplona.quartz.nip01Core.core package com.vitorpamplona.quartz.nip01Core.core
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
actual data class Address actual constructor( actual data class Address actual constructor(
actual val kind: Kind, actual val kind: Kind,
actual val pubKeyHex: HexKey, actual val pubKeyHex: HexKey,
@@ -30,12 +27,6 @@ actual data class Address actual constructor(
) : Comparable<Address> { ) : Comparable<Address> {
actual fun toValue() = assemble(kind, pubKeyHex, dTag) actual fun toValue() = assemble(kind, pubKeyHex, dTag)
actual fun countMemory(): Int =
3 * pointerSizeInBytes +
8 + // kind
pubKeyHex.bytesUsedInMemory() +
dTag.bytesUsedInMemory()
actual override fun compareTo(other: Address): Int { actual override fun compareTo(other: Address): Int {
val result = kind.compareTo(other.kind) val result = kind.compareTo(other.kind)
return if (result == 0) { return if (result == 0) {