perf(chats): hold Set in PrivateChatLazyKey instead of joined String

The previous fix sorted + joined the user pubkeys into a comma-separated
String to keep the key Bundle-storable. That brought back the
StringBuilder + char[] + String + sorted-List allocation per visible
chatroom that the typed-key rework had eliminated.

ChatroomKey.users is often a kotlinx PersistentOrderedSet, which isn't
java.io.Serializable, so we can't just hold the Set reference as-is.
Copying into a HashSet costs one HashMap allocation per key, much less
than the joined-String path, and Set equality stays order-independent so
two equivalent chatrooms still hash to the same bucket.
This commit is contained in:
Claude
2026-04-27 15:47:19 +00:00
parent 298fcb7185
commit 4c6d6eb4b4
@@ -158,7 +158,7 @@ private data class EphemeralChannelLazyKey(
) : ChatroomLazyKey
private data class PrivateChatLazyKey(
val key: String,
val users: HashSet<HexKey>,
) : ChatroomLazyKey
private data class FallbackChatroomLazyKey(
@@ -192,13 +192,10 @@ private fun chatroomLazyKey(
}
is ChatroomKeyable -> {
PrivateChatLazyKey(
event
.chatroomKey(myPubKey)
.users
.sorted()
.joinToString(","),
)
// ChatroomKey.users may be a kotlinx PersistentOrderedSet, which
// is not Serializable. Copy into a HashSet so the key survives
// Bundle round-trips; Set equality stays order-independent.
PrivateChatLazyKey(HashSet(event.chatroomKey(myPubKey).users))
}
else -> {