legacy = UIGraphicsBeginImageContextWithOptions + UIGraphicsEndImageContext
modern = UIGraphicsImageRendererFormat + UIGraphicsImageRenderer
-
"modern" w/
prefersExtendedRange = NO- basically the same perf as "legacy"
- probably a good idea to adopt since optimizations will likely be in "modern" first
-
"modern" w/
prefersExtendedRange = YES- always slower
- between 6 and 9 times slower on actual devices
- usually 20 times slower on simulator (saw 25x regularly in unit tests)
-
"modern" w/
prefersExtendedRange = auto-screen- basically, screens with wide gamut will bucket into YES and others will be NO
-
images w/ wide gamut colorspace
- the image being rendered having wide gamut colorspace or not had no impact on perf
- this seems like an easy optimization that UIKit could add, if the image is not wide gamut, why apply it? The flag is "prefers" extended range after all.
-
reusing the renderer
- this had no impact on performance at all
- the reuse is limited to outputing to the same sized image too, which makes reuse only viable for certain use cases
-
NEW INFO
UIImageoffers the optimalimageRendererFormat(tested asauto-image)- This runs roughly 50% faster than the legacy formatter
- Devs should use legacy on iOS 9 and older
Devs should usedefaultFormat(iOS 10) orpreferredFormat(iOS 11) when creating the UIGraphicsImageRendererFormatDevs should setprefersExtendedRangetoNOwhen the image being rendered is not wide gamut (otherwise, leaveprefersExtendedRangeas the default/auto value)- Devs should use the
imageRendererFormatsourced directly from theUIImagebeing scaled/modified/rendered. It is optimal.