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:
+5
-8
@@ -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 -> {
|
||||
|
||||
Reference in New Issue
Block a user