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 14:12:30 -07:00
parent 7c1594107f
commit 991a4a86e6
50 changed files with 602 additions and 451 deletions

View File

@@ -173,7 +173,7 @@ struct ShareExtensionView: View {
.onReceive(handle_notify(.post)) { post_notification in
switch post_notification {
case .post(let post):
self.post(post)
Task { await self.post(post) }
case .cancel:
self.share_state = .cancelled
dismissParent?()
@@ -193,7 +193,7 @@ struct ShareExtensionView: View {
break
case .active:
print("txn: 📙 SHARE ACTIVE")
state.nostrNetwork.ping()
Task { await state.nostrNetwork.ping() }
@unknown default:
break
}
@@ -216,7 +216,7 @@ struct ShareExtensionView: View {
}
}
func post(_ post: NostrPost) {
func post(_ post: NostrPost) async {
self.share_state = .posting
guard let state else {
self.share_state = .failed(error: "Damus state not initialized")
@@ -230,7 +230,7 @@ struct ShareExtensionView: View {
self.share_state = .failed(error: "Cannot convert post data into a nostr event")
return
}
state.nostrNetwork.postbox.send(posted_event, on_flush: .once({ flushed_event in
await state.nostrNetwork.postbox.send(posted_event, on_flush: .once({ flushed_event in
if flushed_event.event.id == posted_event.id {
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { // Offset labor perception bias
self.share_state = .posted(event: flushed_event.event)
@@ -250,7 +250,7 @@ struct ShareExtensionView: View {
return false
}
state = DamusState(keypair: keypair)
state?.nostrNetwork.connect()
Task { await state?.nostrNetwork.connect() }
return true
}