commit cf904805017f7a32b2f508e9ca77a1e5a87befa4 parent f0075904c273a023d12a9b98e2192e647959939a Author: William Casarin <jb55@jb55.com> Date: Wed, 15 Feb 2023 09:35:10 -0800 perf: decode large events in background threads should help with hitches a bit Diffstat:
M | damus/Nostr/RelayConnection.swift | | | 17 | ++++++++++++++--- |
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/damus/Nostr/RelayConnection.swift b/damus/Nostr/RelayConnection.swift @@ -89,9 +89,20 @@ class RelayConnection: WebSocketDelegate { self.isConnected = false case .text(let txt): - if let ev = decode_nostr_event(txt: txt) { - handleEvent(.nostr_event(ev)) - return + if txt.count > 2000 { + DispatchQueue.global(qos: .default).async { + if let ev = decode_nostr_event(txt: txt) { + DispatchQueue.main.async { + self.handleEvent(.nostr_event(ev)) + } + return + } + } + } else { + if let ev = decode_nostr_event(txt: txt) { + handleEvent(.nostr_event(ev)) + return + } } print("decode failed for \(txt)")