If you’re using ASIHTTPRequest, and haven’t updated your copy recently, there have been a couple of fairly significant changes over the last few months: resuming interrupted downloads and streaming request bodies directly from disk (which should result in big memory savings for iPhone apps). As of today, you can also use different delegates (including progress delegates) for each request in an ASINetworkQueue. As ever, check the changelog for more details.
Also, ASIHTTPRequest is now in the top 20 Objective-C projects on Github! We only need 3573 more followers before DHH starts to worry!
Posted by Ben @ 5:26 PM
Erica Sadun (of iPhone Developer’s Cookbook fame) notes that the Safari 4 Beta application bundle contains a standalone utility for the generating previews of web pages that appear in the top sites view. Rather than generating the previews from the main Safari application process, previews are generated in the backround using a separate process.
My own ASIWebThumbnail uses a similar approach - you add the preview generator application to your bundle, and use the provided API (which talks to it using an NSTask behind the scenes) to talk to it. If you want to generate web page previews in your own Cocoa applications, without worrying about whether some naughty script or plugin will crash your app, you might want to give it a try. (It can also be used standalone from the terminal or from your own scripts)
In the Ars Technica piece, John Siracusa suggests this approach is, in Sadun’s words:
“...a vote of no confidence in Mac OS X’s concurrency frameworks, particularly when used in conjunction with a big library like WebKit.”
Apple notes that WebKit document loading is not safe to use on background threads anyway, which I’m guessing means they’d be looking at UI slowdown if they tried to generate the previews from the main application process. Webkit is a large framework that is not exclusively tied to Mac OS X, so I’m sure making it thread safe would be a massive undertaking.
Such a large piece of software is also bound to contain some bugs, and the modern web is basically one giant blob of unexpected input, waiting to crash your software in multifarious ways. Additionally, browsers have to contend with Adobe Flash third-party plugins that might contain crashing bugs. Even if Webkit were thread safe, why take the risk for something like as trivial as web page previews?
Of course, Apple weren't exactly the first to realise that a multi-process browser might offer some stability advantages. Surely it won't be long before both Safari and Firefox start handing off responsibility for each web view to a new process, as Google and Microsoft have done.
NSOperation and NSOperationQueue, introduced in Mac OS X 10.5 and also available on iPhone, offers a nice model(i) for handling sets of tasks across multiple cores, but they still require you to have a reasonable understanding of threading concepts like locks except in trivial cases. If your application has a UI, you’ll also generally need to take care to update it only on the main thread. Given that most modern desktop computers have at least two cores (more if you count the GPU), surely we must be overdue for some easier methods for our to software get the most out of the available hardware?
Aaaron Hillegass’s definitive Cococa Programming For Mac OS X touches on some of the problems surrounding multithreaded programming, summarised with the the following pearl of wisdom (page 406 in 3rd Edition):
“Although not as glamourous as multithreading, multiprocessing is probably more useful in real life.”
When I first saw this, I wondered why he would suggest such a thing. Surely, the standard way of getting desktop software to do more than one thing at once is using threads, not using multiple processes?
At last, I think I finally understand his point.
I don’t have a copy of Snow Leopard, so I don’t know anything about what’s coming in Grand Central, other than the somewhat sketchy information Apple have supplied to the public. Will this finally make multi-core programming easy? And how (if at all) will this technology be translated to the iPhone?
Posted by Ben @ 5:50 PM
ASIHTTPRequest is now using the amazing GHUnit I was talking about only the other day.
As well as the nice user interface and easy test debugging that GHUnit provides, I've been able to get all the tests running in the iPhone simulator too.
More information is as ever available in the Changelog.
If you haven’t tried GHUnit yet, you really should.
Posted by Ben @ 3:03 PM
If you've ever tried to setup unit tests in Xcode, you'll know what a PITA they can be, especially when it comes to trying to debug your tests (though Chris Hanson’s wonderful guides make this convoluted process just about understandable for mere mortals like me).
Gabriel Handford’s GHUnit is a unit testing framework with its own user interface, and is well worth a look. You can make tests by subclassing GHTestCase, but it also supports SenTestCase and GTMTestCase subclasses, and I was able to get the ASIHTTPRequest tests up and running in no time at all. There’s even a UI for running tests in the iPhone simulator (I haven’t tried this yet).
I can see loads of potential for this project, and it’s already so much nicer than SenTestingKit. The source is on Github.
Via: Michael Tsai
Posted by Ben @ 6:02 PM
ASIHTTPRequest now supports gzip compressed responses, using zlib, which should help speed up downloads, particularly in iPhone applications where bandwidth is at a premium. More information is available in the changelog.
My thanks once again to Shaun Harrison at Enormego for the code he contributed.
Posted by Ben @ 2:40 PM