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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user