Re: Data downloading performance
Re: Data downloading performance
- Subject: Re: Data downloading performance
- From: Kyle Sluder <email@hidden>
- Date: Fri, 16 Jul 2010 23:02:03 -0700
On Fri, Jul 16, 2010 at 10:36 PM, Rafael Cerioli
<email@hidden> wrote:
> I guess I had something wrong, NSURLConnection does not do anything in a
> background thread. It just operates in the main thread but "asynchronously"
> thanks to the run loop.
Well, sort of. I believe what actually happens is that it uses a
private helper thread to perform the communication but notifies its
delegate on the main thread. But that's an implementation detail that
I might well have wrong. All that matters is that something gets
scheduled on the calling thread's runloop that is responsible for
notifying the delegate.
> Quote from NSURLConnection class reference :
> "At creation, a connection is scheduled on the current thread (the one where
> the creation takes place) in the default mode"
> That means, there is a lot of work done in the main thread. Even if the
> connection is not scheduled in the runloop "tracking" mode (for the UI), I
> guess the app would slow down at some point.
Guessing is not helpful. Start at the highest level of abstraction. If
you can demonstrate with actual data that it poses a problem, then
remove one layer of abstraction.
> Isn't it better to use -[NSData initWithContentOfURL:] synchronous load
> method in background thread ?Or is there something wrong about that kind of
> use ?
It uses NSURLDownload, which has had its own share of problems:
http://lists.apple.com/archives/Cocoa-dev/2007/Jun/msg00117.html
In general, the answer to your Cocoa problems is not "spawn a thread."
> By the way, I never seen any bug about NSURLConnection running in background
> threads on iPhone OS.
See above, but also here for the exact backtrace:
http://lists.apple.com/archives/cocoa-dev/2008/May/msg03073.html
Again, this may have been fixed, the whole asynchronous thing might be
a red herring for a more pervasive bug that also affects asynchronous
use of the API, or (miracle of miracles) the bugs may have been fixed.
But the received wisdom is do not use NSURLConnection synchronously,
especially since it doesn't really give you any benefit to start with.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden