Begin main content

Faster JavaScript with Safari/WebKit SquirrelFish

WebKit logoWebkit is the opensource engine behind Apple's Safari web browser for Mac, PC and the iPhone. Originally based on the KHTML engine from the KDE project, it has seen rapid development since the Safari 2.0 days.

In June, the project announced SquirrelFish, the oddly named next-gen JavaScript engine which includes bytecode compilation and a number of optimisations. The announcement indicates a 1.7 x speed increase over the engine in Safari 3.0. My perceptual testing on my (admittedly low baseline) G4 PPC powerbook suggests that startup time of JavaScript intensive applications such as Gmail improves only a little (saving 1 second off the 9 second startup time), but the ongoing performance is much snappier. Things like Flickr badges load in a snap.

It is good to get closer to the performance Firefox 3.0 which has the maddening property that it starts out very fast (7 second Gmail startup), but a large amount of JavaScript intensive browsing brings it to its knees over time - something Safari suffers far less from.

You can get a hold of the new engine by downloading the WebKit knightly build from http://webkit.org/

05:59 AM, 24 Aug 2008 by Mark Aufflick Permalink | Comments (0)

Testing database deadlock retry logic

I just spent a *really* long time writing a test for automatic deadlock retry in a database api module I maintain. So you or I don't have to figure it out in the future, here's the recipe.

So firstly you can't use transactions to build the deadlock situation. That would be easy, but it defeats our purpose since your auto-deadlock retry logic is not going to be able to retry intra-transaction statements (of course you could implement full transaction replay, but that's another story).

So I did it using cursors. Here is a perl sub that builds Sybase TSQL. It returns two values only because Sybase requires the cursor declaration in a separate batch.

sub deadlock_sql {
    my ($table1, $table1_char_col, $table2, $table2_col) = @_;
    
    "declare the_cursor cursor for select $table1_char_col from $table1 for update",
    sprintf 'declare @col_value varchar(100)
             open the_cursor

             fetch the_cursor into @col_value
             waitfor delay "00:00:04" -- wait 4 seconds
             update %s set %s = %s
             -- only need to go round once to cause deadlock
             ', $table2, $table2_col, $table2_col;
}
So we are taking out a write lock on the first table, waiting 4 seconds, then taking out a write lock on the second table. Do that twice in opposite order and you have yourself a deadlock:
sub cause_a_deadlock {
    
    my $child_pid;
    my $parent_retries;
    
    pipe(FROM_CHILD, TO_PARENT);
    
    if ($child_pid = fork) {
    
        # parent
    	
        close(TO_PARENT);
       
       my $dbh = new_dbh();
       my @sql = deadlock_sql('table1', 'a_char_col_from_table1', 'table2', 'any_col_from_table_2');
       
       sleep 2; # sleep half of sql sleep to ensure overlap
       
       $dbh->exec_sql($sql[0]);
       lives_ok { $dbh->exec_sql($sql[1]) };
       
       $parent_retries = $dbh->deadlock_retry_attempts;
       
   } else {
   
       # child
       
       close(FROM_CHILD);
       
       my $dbh = new_dbh();
       my @sql = deadlock_sql('table2', 'a_char_col_from_table2', 'table1', 'any_col_from_table_1');
       
       $dbh->exec_sql($sql[0]);
       lives_ok { $dbh->exec_sql($sql[1]) };
       
       print TO_PARENT $dbh->deadlock_retry_attempts . "\n";
       
       exit;
   
   }
   
   my $child_retries = <from_CHILD>;
   chomp($child_retries);
   close(FROM_CHILD);
   
   waitpid $child_pid, 0;
   
   # we don't know which spid was aborted & retried, but one was
   ok($parent_retries + $child_retries > 0, 'there were deadlock retries');
   is($parent_retries, 0, 'only the child had to retry') if $child_retries;
   is($child_retries, 0, 'only the parent had to retry') if $parent_retries;
}

Of course the exact code will depend on your database and database abstraction layer.

05:35 AM, 20 Aug 2008 by Mark Aufflick Permalink | Comments (0)

5 years and still blogging

August 2003 saw the start of this weblog. My first blog was in 2002 when I visited Denmark to do some work with my friend Lars, but when I shut that down after my travels I neglected to save the contents. So instead I will call this the fifth year of my blogging.

Who would have predicted that the SCO law suits I blogged about in that first month would still be going.

Perhaps more predictably, the Be company, blogged about in my second month, would go under.

Also predictably I have less time for blogging now that I have a "real" job and am also studying part time.

Thanks to everyone who ever commented and all my regular readers (I count 3 - am I missing anyone?). I enjoy writing, so you'll be sure to keep hearing from me well into the future.

I plan to list a few favourite posts a little later and thank some inspirations. Hey - any excuse!

05:52 AM, 09 Aug 2008 by Mark Aufflick Permalink | Comments (4)

August == Skiing

Well it's August and that means skiing :) Some of you will know that I had a day of blissful snow in NZ in June, but next week Kath and I head to Thredbo for nearly a full week of hounding powder - and there's stacks of it too!

This was NZ - sounds like Thredbo will be just as good:

05:44 AM, 09 Aug 2008 by Mark Aufflick Permalink | Comments (0)

XML

Blog Categories

software (41)
..cocoa (23)
  ..heads up 'tunes (5)
..ruby (6)
..lisp (4)
..perl (4)
..openacs (1)
mac (21)
embedded (2)
..microprocessor (2)
  ..avr (1)
electronics (3)
design (1)
photography (26)
..black and white (6)
..A day in Sydney (18)
..The Daily Shoot (6)
food (2)
Book Review (2)

Notifications

Icon of envelope Request notifications

Syndication Feed

XML

Recent Comments

  1. Mark Aufflick: Re: the go/Inbox go/Sent buttons
  2. Unregistered Visitor: How do make a button to jump to folder
  3. Unregistered Visitor: Note I've updated the gist
  4. Unregistered Visitor: umbrello is now an available port on macPorts
  5. Unregistered Visitor: Updated version on Github
  6. Unregistered Visitor: Modification request.
  7. Unregistered Visitor: Accents and labels with spaces
  8. Unregistered Visitor: Mel Kaye - additional info
  9. Unregistered Visitor: mmh
  10. Mark Aufflick: Thank you