MugunthKumar/MKNetworkKit — pull request #65 by ayoy (2012-02-26 22:23:13+00:00)
Title: Caching cURL command line string and unique identifier of MKNetworkOperation

* Recreate cURL command line string and unique identifier each time
any header field changes or a new file is attached
* Recreate `uniqueIdentifier` each time cURL command line string changes
* This brings significant speed-up to `MKNetworkOperation`'s `isEqual:`
which is a bottleneck of `enqueueOperation:forceReload:` (called multiple
times when operation is being located in the shared queue)

----------
In cases when you send out large number of requests at once (e.g. to download 100 image thumbnails), the original thread (in most cases the main thread) is blocked for some time when `MKNetworkEngine` checks if the operation hasn't already been queued (call to `[_sharedNetworkQueue.operations indexOfObject:operation]`). This calls `isEqual:` on `MKNetworkOperation` multiple times, and each time `uniqueIdentifier` is recreated.

My solution is to recreate curl command string and `uniqueIdentifier` as `MKNetworkOperation` is configured, for them to be ready once it's being enqueued. Of course it brings the overhead of computing these two values each time HTTP headers are modified, but it's still worth it taking into account most possible use cases:
* when application sends out one simple request from time to time it does no harm at all
* when application sends out one complex request from time to time it's probably anyway created in a separate thread so still no harm
* when application sends out multiple requests at once, this optimization greatly reduces the need to introduce threading code

Cheers,
Dominik