Skip to content

Commit

Permalink
Skip decompression for .png images
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Apr 20, 2024
1 parent a1a640b commit bafe72c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Sources/Nuke/Processing/ImageDecompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
import Foundation

enum ImageDecompression {
static func isDecompressionNeeded(for response: ImageResponse) -> Bool {
guard response.container.type != .png else {

This comment has been minimized.

Copy link
@Pash237

Pash237 May 30, 2024

In my case this moves image decoding from multiple background threads to the main thread causing frame drops :(

Time Profiler before:
before

Time Profiler after:
after

This comment has been minimized.

Copy link
@kean

kean May 30, 2024

Author Owner

Thanks for the report!
Would you mind opening an issue and attaching one of the images in question?

It seems like it might be worth reverting this for further investigation and/or making this opt-in.

This comment has been minimized.

Copy link
@Pash237

Pash237 May 30, 2024

Done! #788
Thank you for quick response!

// Attempting to decompress a `.png` image using
// `prepareForReuse` results in the following error:
//
// [Decompressor] Error -17102 decompressing image -- possibly corrupt
//
// It's also, in general, inefficient and unnecessary.
return false
}
return isDecompressionNeeded(for: response.image) ?? false
}

static func decompress(image: PlatformImage, isUsingPrepareForDisplay: Bool = false) -> PlatformImage {
image.decompressed(isUsingPrepareForDisplay: isUsingPrepareForDisplay) ?? image
Expand Down
6 changes: 2 additions & 4 deletions Sources/Nuke/Tasks/TaskLoadImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ final class TaskLoadImage: ImagePipelineTask<ImageResponse> {
}

private func isDecompressionNeeded(for response: ImageResponse) -> Bool {
!isEphemeral &&
(ImageDecompression.isDecompressionNeeded(for: response.image) ?? false) &&
ImageDecompression.isDecompressionNeeded(for: response) &&
!request.options.contains(.skipDecompression) &&
!isEphemeral &&
pipeline.delegate.shouldDecompress(response: response, for: request, pipeline: pipeline)
}

Expand All @@ -152,9 +152,7 @@ final class TaskLoadImage: ImagePipelineTask<ImageResponse> {
guard !isEphemeral else {
return // Only store for direct requests
}
// Memory cache (ImageCaching)
pipeline.cache[request] = response.container
// Disk cache (DataCaching)
storeImageInDataCache(response)
}

Expand Down

0 comments on commit bafe72c

Please sign in to comment.