Slow performance decoding large images with Core Image.

I'm building a camera app that does some post processing after the photo has been taken. With 12MP the processing is pretty good, but larger images 24MP is very slow.

I created a very simple example to demonstrate the issue, which is loading an image and the rendering it to data.

 let context = CIContext()

let imageUrl = Bundle.main.url(forResource: "12mp", withExtension: "jpg")!
let data = try! Data(contentsOf: imageUrl)

let ciImage = CIImage(data: data)!
            
let start = CFAbsoluteTimeGetCurrent()
            
let data = context.jpegRepresentation(of: ciImage, colorSpace: context.workingColorSpace!)
            
print(data?.count)
print("Resize Completed: " + String(CFAbsoluteTimeGetCurrent() - start))

Running this code on an iPhone 16 Pro with different images produces these benchmarks:

  • 12MP => 0.03s
  • 24MP => 1.22s
  • 48MP => 2.98s

I understand that processing time will increase with resolution but it doesn't seem linear. I have tried setting different CiContext options such as .useSoftwareRenderer: false but it has made no difference.

From profiling the process it looks like the JPEG decoding is the bottle neck. This is for a 48MP Image:

Is there any way this can be improved?

Slow performance decoding large images with Core Image.
 
 
Q