Move most of RelayPool away from the Main Thread

This is a large refactor that aims to improve performance by offloading
RelayPool computations into a separate actor outside the main thread.

This should reduce congestion on the main thread and thus improve UI
performance.

Also, the internal subscription callback mechanism was changed to use
AsyncStreams to prevent race conditions newly found in that area of the
code.

Changelog-Fixed: Added performance improvements to timeline scrolling
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2025-10-10 16:38:48 -07:00
parent 7c1594107f
commit 991a4a86e6
50 changed files with 602 additions and 451 deletions
@@ -34,7 +34,7 @@ func migrate_old_muted_threads_to_new_mutelist(keypair: Keypair, damus_state: Da
let previous_mute_list_event = damus_state.mutelist_manager.event
guard let new_mutelist_event = create_or_update_mutelist(keypair: fullKeypair, mprev: previous_mute_list_event, to_add: Set(mutedThreads.map { MuteItem.thread($0, nil) })) else { return }
damus_state.mutelist_manager.set_mutelist(new_mutelist_event)
damus_state.nostrNetwork.postbox.send(new_mutelist_event)
Task { await damus_state.nostrNetwork.postbox.send(new_mutelist_event) }
// Set existing muted threads to an empty array
UserDefaults.standard.set([], forKey: getMutedThreadsKey(pubkey: keypair.pubkey))
}
@@ -87,7 +87,7 @@ struct AddMuteItemView: View {
}
state.mutelist_manager.set_mutelist(mutelist)
state.nostrNetwork.postbox.send(mutelist)
Task { await state.nostrNetwork.postbox.send(mutelist) }
}
new_text = ""
@@ -30,8 +30,10 @@ struct MutelistView: View {
}
damus_state.mutelist_manager.set_mutelist(new_ev)
damus_state.nostrNetwork.postbox.send(new_ev)
updateMuteItems()
Task {
await damus_state.nostrNetwork.postbox.send(new_ev)
updateMuteItems()
}
} label: {
Label(NSLocalizedString("Delete", comment: "Button to remove a user from their mutelist."), image: "delete")
}