Nuke 6.0 π
About 8 months ago I finally started using Nuke in production. The project has matured from a playground for experimenting with Swift features to something that I rely on in my day's job.
There are three main areas of improvements in Nuke 6:
- Performance. The primary
loadImage(with:into:)
method is now 1.5x faster thanks to cumulative performance improvements toCancellationToken
,Manager
,Request
andCache
. And it's not just main thread performance, many of the background operations were also optimized. - API refinements. Some common operations that were surprisingly hard are easy now. And there the implementation details are no longer leaking into a public API (e.g. classes like
Deduplicator
). - Fixed inconveniences like Thread Sanitizer warnings (false positives!). Improved compile time. Better documentation.
New APIs
- Implements progress reporting #81
- Scaling images is now easier and more discoverable with new convenience
Request
initialisers (Request.init(url:targetSize:contentMode:
andRequest.init(urlRequest:targetSize:contentMode:
) - Add a way to add anonymous image processors to the request (
Request.process(key:closure:)
andRequest.processed(key:closure:)
) - Add
Loader.Options
which can be used to configureLoader
(e.g. change maximum number of concurrent requests, disable deduplication or rate limiter, etc).
Improvements
- Improve
CancellationTokenSource
,Loader
,TaskQueue
,Manager
,Request
,Cache
performance - Parallelize image processing for up to 2x performance boost in certain scenarios. Might increase memory usage. The default maximum number of concurrent tasks is 2 and can be configured using
Loader.Options
. Loader
now always calls completion on the main thread- Move
URLResponse
validation fromDataDecoder
toDataLoader
- Make use of some Swift 4 feature like nested types inside generic types
- Improve compile time
- Wrap
Loader
processing and decoding tasks intoautoreleasepool
which reduced memory footprint
Fixes
- Get rid of Thread Sanitizer warnings in
CancellationTokenSource
(false positive) - Replace
Foundation.OperationQueue
& customFoundation.Operation
subclass with a newQueue
type. It's simpler, faster, and gets rid of pesky Thread Sanitizer warnings #141
Removed APIs
- Remove global
loadImage(...)
functions #142 - Remove static
Request.loadKey(for:)
andRequest.cacheKey(for:)
functions. The keys are now simply returned inRequest
'sloadKey
andcacheKey
properties which are also no longer optional now. - Remove
Deduplicator
class, make this functionality part ofLoader
. This has a number of benefits: reduced API surface, improves performance by reducing the number of queue switching, enables new features like progress reporting. - Remove
Scheduler
,AsyncScheduler
,Loader.Schedulers
,DispatchQueueScheduler
,OperationQueueScheduler
. This whole infrastructure was way too excessive. - Make
RateLimiter
private DataLoader
now works withURLRequest
, notRequest