damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 0bea81c632727cbb6479c3f239775e94c3a79d4a
parent e4842cca3c7e6b1af276428ed1013649b702cb9b
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 20 Jun 2023 16:28:22 +0200

perf: move blurhash processing to a background task

Using Task directly will only inherent the parent thread. We need
detached to do heaving processing.

Diffstat:
Mdamus/Util/Images/ImageMetadata.swift | 6++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/damus/Util/Images/ImageMetadata.swift b/damus/Util/Images/ImageMetadata.swift @@ -59,17 +59,15 @@ struct ImageMetadata: Equatable { } func process_blurhash(blurhash: String, size: CGSize?) async -> UIImage? { - let res = Task.init { + let res = Task.detached(priority: .low) { let size = get_blurhash_size(img_size: size ?? CGSize(width: 100.0, height: 100.0)) guard let img = UIImage.init(blurHash: blurhash, size: size) else { let noimg: UIImage? = nil return noimg } - return img } - return await res.value } @@ -146,7 +144,7 @@ func calculate_blurhash(img: UIImage) async -> String? { return nil } - let res = Task.init { + let res = Task.detached(priority: .low) { let bhs = get_blurhash_size(img_size: img.size) let smaller = img.resized(to: bhs)