From 4c6d6eb4b46208485a7ef551e2b844e2c3fff897 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Apr 2026 15:47:19 +0000 Subject: [PATCH] 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. --- .../chats/rooms/feed/ChatroomListFeedView.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt index 801d80555..300f36eda 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt @@ -158,7 +158,7 @@ private data class EphemeralChannelLazyKey( ) : ChatroomLazyKey private data class PrivateChatLazyKey( - val key: String, + val users: HashSet, ) : 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 -> {