Friday, April 02, 2010

node.js - Evidence CPS is ideal for high performance?

I stumbled on the Node.js project today. For those, like myself who had never heard of it, it's a project that attempts to support high performance applications. It does so by making all IO calls non-blocking. From their docs, you see that:

  var result = query("SELECT * FROM ...");
  // do stuff

turns into:

 query("SELECT * FROM ...", 
   function(result) { 
    // do stuff 
   });

As JavaScript and ActionScript have shown, with calls written in this style, concurrency can be pretty much hidden from the user.

Whenever I see code in the above shape, I can't help but think of Continuation Passing Style (CPS), as that's essentially what's going on. What I like about CPS is that you can provide a level of explicitness not often found in code. For example, you might rewrite the query function above to have the signature:

 function query(sql, onSuccess, onNoRows, onFailure) { ... }

In order to use this function, you require the user to think through how they are going to handle the different scenarios.

Though, my take away from reviewing the node.js project is that along with a style boost, CPS may also be a path to a performance boost.

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails