Tim Disney

Branch-Hacking

This.

The SOPA/PIPA protests today were necessary but ultimately an exercise in branch-hacking. If SOPA is defeated it’ll be reborn in a year with a different name (just as PIPA is the new COICA).

It’s time to strike the root.

Performance of contracts.coffee

I’ve been meaning to get around to running some performance benchmarks on contracts.coffee, but I recently learned a valuable lesson: let the internet do your work for you! :-)

I woke up this morning to find @paulmillr had put together a nice performance benchmark of contracts.coffee.

Check it out for all the gory details but suffice it to say contracts makes things…slow. This is about what I’d expected since in addition to running the actual contract check we must wrap the contracted functions/objects in a Proxy which runs handlers for each function call or property set/get. Lots of stuff is in the way of the running code.

So does the slow performance of contracts make them unusable? Not necessarily. First off, the contracts.coffee compiler can emit JavaScript with contracts completely disabled. So, you can have a “slow” testing/development build with contracts enabled to help track down bugs and a production build with contracts disabled and no slowdown.

In addition, most code is IO bound not CPU bound. So if you want contracts enabled everywhere but still care about performance, be smart about where you apply them. Put them on module boundaries, but don’t put them on tight loops for example.

In sum, contracts are another tool in the software engineer’s toolbox that have advantages (bug squashing) and disadvantages (performance slowdowns when enabled). Use them wisely.

Contracts.coffee Works In Node.js!

Contracts.coffee now works in node.js! V8 (the JavaScript engine used by node) has recently added support for Proxies which contracts.coffee requires.

You’ll need a bleeding-edge version of node to get it running. Try either master (unstable) or 0.5.7. Build instructions are here.

Proxies are hidden behind a command line flag in V8 so you’ll also need to supply --harmony_proxies to node when calling the compiler:

node --harmony_proxies bin/coffee -CL test.coffee

There are almost certainly node-specific bugs in contracts.coffee so don’t trust it with anything important yet. You can get started playing though!

Report any bugs you run into on the issue tracker.

Subscribe to new posts here.
For older posts see the archive