perf: move blurhash processing to a background task
Using Task directly will only inherent the parent thread. We need detached to do heaving processing.
This commit is contained in:
1 parent
e4842cca3c
commit
0bea81c632
1 file changed
+2
-4
@@ -59,17 +59,15 @@ struct ImageMetadata: Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func process_blurhash(blurhash: String, size: CGSize?) async -> UIImage? {
|
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))
|
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 {
|
guard let img = UIImage.init(blurHash: blurhash, size: size) else {
|
||||||
let noimg: UIImage? = nil
|
let noimg: UIImage? = nil
|
||||||
return noimg
|
return noimg
|
||||||
}
|
}
|
||||||
|
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return await res.value
|
return await res.value
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +144,7 @@ func calculate_blurhash(img: UIImage) async -> String? {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = Task.init {
|
let res = Task.detached(priority: .low) {
|
||||||
let bhs = get_blurhash_size(img_size: img.size)
|
let bhs = get_blurhash_size(img_size: img.size)
|
||||||
let smaller = img.resized(to: bhs)
|
let smaller = img.resized(to: bhs)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user