Two great authors

If you at all enjoy the science fiction genre two authors you must read
All of their books are good but if you've never read them I'd start with "Pandoras Star" (Hamilton) and "A Deepness in the Sky" (Vinge)


Blocks Break Even point.

Something a little different today -- A few experiments using Snow Leopards GCD
Perhaps someone will come along and prove my methodology wrong -- I'm just trying to get a simple 'gut' feel for how well GCD performs and what the 'break even' is

I wrote a simple cocoa app that does a trivial thing -- It starts a timer, then pushes a request to a background thread who's only job is to call the foreground thread to stop the timer.  Below is the code snippit of interest.

-(BOOL) finish {
stopTime=[NSDate timeIntervalSinceReferenceDate];
NSLog(@"time was %f",stopTime-startTime);
return TRUE;

/********* using GCD *************/

-(IBAction) gcd:(id) sender {
startTime=[NSDate timeIntervalSinceReferenceDate];
dispatch_queue_t bgQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(bgQueue , ^{
        dispatch_async(dispatch_get_main_queue(), ^{
[self finish];
-(void) _bg {
[self performSelectorOnMainThread:@selector(finish) withObject:nil waitUntilDone:NO];

/******** Using Perform Selector ***********/

-(IBAction) bg:(id) sender {
startTime=[NSDate timeIntervalSinceReferenceDate];
[self performSelectorInBackground:@selector(_bg) withObject:nil ];

/******** Direct Call *************/
-(IBAction) no:(id) sender {
startTime=[NSDate timeIntervalSinceReferenceDate];
[self finish];

/********** Using Threads ***********/
-(IBAction) _thread {
NSAutoreleasePool *pool=[NSAutoreleasePool new];;
[NSThread detachNewThreadSelector:@selector(finish) toTarget:self withObject:nil];
[pool release];

-(IBAction) thread:(id) sender {
startTime=[NSDate timeIntervalSinceReferenceDate];
[NSThread detachNewThreadSelector:@selector(_thread) toTarget:self withObject:nil];

I actually wrote this 4 ways -- One using the 'blocks' feature, one using 'performSelector', one using NSThread and one that calls 'doit' by itself.  All tests were run on a 8 core Mac Pro (16 virtual cores) at 2.66GHz (this is the current as of this writing Mac Pro).

I also took three measure (the code above doesn't show all of the measurements):

  1. The amount of time to push the work to the background and return
  2. The amount of time to execute a trivial instruction in the background
  3. The amount of time to push to the background and then instantly push a trivial instruction back on the main thread

The results?

Time to push to background & return
Time to execute in background
Time to push to background, execute in background and push results to main thread
 Threads (NSThread)58103198
No threading/backgroundingNANA<1

Bottom line?  GCD offers decent performance improvements over conventional approaches. But even with it's improved performance it's overhead is equal to 'hundreds' of method calls (on my test system I can call > 200 methods in 13us) so if your goal is to offload work you would need to already be facing 100us length tasks (e.g. IO, networking, long computation) before it's clearly a win -- Nothing really new here on that conclusion however as that's always been true with multiple threads

I suspect that cocoa now uses GCD under the hood for a lot of it's work so it's not suprising that the various methods all time in about the same -- I'd be curious to see this run on Leopard (but not curious enough to re-boot into leopard!)
Finally the question could be asked:  How much work would it take before the work equaled the overhead of backgrounding?   I wrote  simple loop to just spin until  the timer reached 150us

-(IBAction) loop:(id) sender {
int i;
startTime=[NSDate timeIntervalSinceReferenceDate];
while ([NSDate timeIntervalSinceReferenceDate]-startTime <150e-6) i++;
NSLog(@"number of iterations was %d",i);

It turns out to be about 2400 iterations for 150us.

A final note -- I'm testing the case of pushing work off on a background thread to improve the user experience -- clearly there are examples of multithreaded applications where you want to maximize processor utilization or set up a complicated processing chain that this analysis doesn't apply to.

My 'walk away' is you need to perform thousands of method calls before you reach the break even point for using any threading or background tasks.
Comments (2)

Snow Leopard

Believe it or not my favorite Snow Leopard feature is image capture.

It now recognizes my scanner (an HP PhotoSmart all-inone) and does a credible job of scanning PLUS you can now choose what to do when a given device (camera) is attached (launch iPhoto, do nothing, etc.)

What's especially nice is the network scanning feature is not natively supported (my printer is network capable and any mac on my network can now scan directly)

It's never mentioned but if you haven't check out Image Capture -- It's become a very nice utility for photos & scanning.

Snow Leopard

This morning Apple announced that Snow Leopard is available this friday, the 28th.  It's sort of amazing how differently Apple announces os.  I mean they are announcing it's availability 5 days before they ship a brand new version of their OS.

I've been using Snow Leopard (from now on referred to as SL) for a few weeks to make sure my plugins are all working.  So far it's all gone smoothly but I'll be planning some extra time this weekend to quick fix any problems discovered.

I wish I could share more about SL as I do have a few things to say but I'll honor my NDA and wait until after it ships.....

I am so Weak V3.0

Just purchased my iPhone 3Gs -- For the THIRD time I swore I wasn't going to get a new phone s the changes weren't big enough (original iPhone & iPhone 3G) but once again I got distracted the shiny newness.
I hope Apple never starts making Cars........
Comments (1)

WWDC Wrap Up

It's the last day of WWDC and I just finished my last session -- I thought I would share with you, my loyal reader, a few thoughts on WWDC.
As you probably know, WWDC is Apple's "World Wide Developers Conference". It's organized around three tracks: Mac, iPhone & IT. There is usually some stuff that crosses two of the three (for instance this year a number of sessions had info relevant for both iPhone & Mac, or Mac & IT.)
The sessions are organized into 75 minute blocks, with two in the morning and three in the afternoon -- They leave a generous amount of time for lunch (but usually have guest speakers) and there are many social activities in the evening (the only apple sponsored one is the 'bash' on thursday -- the rest of organized by various parties)
This is my third year going so I've begun to see some interesting patterns. For instance there are the folks who go mostly for social reasons -- They typically miss the morning session because they were out too late -- Often skip afternoon sessions and in general can be found surrounded by a group of people chatting it up.
Then there are the IT guys -- I really feel sorry for them because there really aren't that many sessions that are just IT specific so you often find them going to technical sessions. Some of them are pretty sharp and can follow along but often times it's stuff that that they just don't use enough so it makes it hard for them to follow along.
Then there are the corporate types -- People who's company sent them. They tend to hang around other people from their team and are pretty picky about which sessions they chose (and will skip sessions if there is nothing relevant to what they do) -- You can usually spot them because they are running entourage checking email constantly.
Finally the intense 'go to every session' guys -- that's where I fall -- I tend to attend every session (even if the choices are not terribly interesting to me).
Finally there are the labs -- I've always heard that the labs area a great resource but I've never used them much. In the labs the Apple engineers around a certain technology get together at a certain time and you can bring your problems and they'll help you fix them. This year for the first time I had a problem that I didn't have a good solution for and so I went to the labs. It worked out really well as I got to speak directly to the experts who gave me some really good ideas.
I wish I could talk about what I learned this year -- there are some exciting technologies in Snow Leopard that I really think will change the kinds of apps you can easily do so I'm really looking forward to it's release.
Ciao for now..

Last Comment!

No -- This is not the last post on this blog -- instead I'm referring to the fact that I got the last post on this comment thread (before they closed comments)
In case you haven't been following I've made a iPhone app for managnig your dreamhost account -- Initially it was spurred on by the 'crazy contest' but I actually had a lot of fun working on it (especially with a deadline -- honestly I do my best work under pressure)
My resulting app is called "DreamApp" and it's not too bad (if I do say so myself) -- Last night I debated on if I should put it on the app store or wait until after WWDC. I'll probably wait until after WWDC because I may learn some cool tricks to make it even nicer (and quite frankly releasing something before WWDC is a bad idea as your brain is generally pretty fried that week)
Speaking of which I'll be at WWDC next week -- Great Fun (most of which I can't talk about) and a nice time to meet up with some of my mac geek friends -- (in the picture from left to righ. Fraser Spiers, Me, Isaiah, some unknown tall guy -- from last years WWDC)

The holy trinity of working on more than one Computer

Like perhaps many of you I live & work on multiple computers. It's almost a embarassing but I have
  • A Mac Pro as my main development machine (and is it ever sweet!)
  • A HP laptop at my 'day job' (While it certainly doesn't have the stylings of Apple it's actually quite a nice machine)
  • A Macbook pro for when I'm away from home
  • A Hackintosh MSI Wind that I use for fun
Crazy -- Four computers for one guy but there you have it. For the most part I can keep my work PC and Macs separate -- I usually don't need to share files back and forth and on the odd day i do need to share I usually end up emailing myself (or a USB thumbdrive) - A little awkward but it gets the job done.
My Macs are a different issue all together -- It's horrible to be working day in and day out on one computer (my 'pro) and then have to prepare a laptop for a long weekend away. I *always* forget to transfer something and when I'm away I'm always fretting that I am editing a old version of a file and then coming home is terrible -- I need to remember to transfer them back.
I've come across four solutions, however, that almost perfectly fix my problem and make multiple macs (or to a large extent PC's) sync up perfectly. They are DropBox, Evernote, & Mobile Me.
DropBox is the home run of this solution -- I had tried it about 6 months ago an uninstalled it as it seemed to be a resource hog (chewing up tons of CPU, bandwidth & memory). Since then the dropbox folks have done a lot (plus I've upgraded my hardware) so now it runs like buttah. You just store files in your dropbox on your PC and amazingly fast they get synced. Open up another computer and it syncs that. It even works on my work PC so I've begun to keep all my documents in my dropbox to have always access.
The other thing dropbox does is keep revisions -- If you modify or delete a file you can go online and restore it (I'm not sure how far back they keep them -- I suspect they keep them until you run up against your limit)
DropBox is free for 2GB accounts and $99/yr for 50GB accounts.
Evernote is a notes taking application -- They have a great iPhone, Mac & PC client and I use it to scribble things down. Like dropbox it works like magic and it's replaced my various folders of text documents, outlook items, etc. Evernote is free but there is a premium service for (I think) $49/yr that increases the size of notes as well as attach arbitrary files (so you can embed a PPT along with the note)
Finally mobile me. At this point I use it for calendar, address book and preferences syncing across macs and my iphone. It works pretty well for this but at you can get the address book and calendar syncing through google so the preference & keychain syncing is the only thing I use it for with multiple computers. I do occasionally use back to my mac which is nice but honestly I hope apple finds a way to make it more valuable otherwise they may not see my $99 come september.
Of the four DropBox and Evernote are my most favorite -- They work amazingly well and are free (but both offer paid upgrades with enhanced capacity & storage)
Highly recommended.
Comments (2)

Newest Project (DreamHost customers read!)

I've been playing with a new project recently -- I honestly never intended for this to turn into anything "real" but somehow it took on a life of it's own. If you use DreamHost as your web host you might be interested in looking at this -- It's a domain & list management application for dreamhost accounts (and I must say that it's turning out pretty slick) If you want to help finish it via beta testing send me a note.
Comments (2)

Drawing Mode

Google just released a 'drawing mode' in google docs. While it certainly won't replace Adobe Illustrator it's still a amazing achievement for an online word processor and should be quite handy to toss up a few quick diagrams to explain a point.
Of course I've updated PlusKit to work with it -- Grab 1.58 and enjoy all of the drawing goodness.
Comments (1)

Next Page -->