Script Support in Firebase

Now we have released a candidate for script support in Firebase! This is something we’re very excited about as it means no more Java (unless you want to of course, old hands like me aren’t likely to change in a hurry).This is a first release so there’s no support for tournaments or services yet. But is not far off.We’re using Java’s built in scripting support under the hood. It turned out to be not to trivial, but not very hard either. The interesting issues are likely to arrive when we start optimizing and bug hunting. And speaking of optimizing, I ran a few bots, say 50, against a very small script (basically the equivalent of a hello world) and on avarage the bots returned on 10 ms. That’s 10 ms for network latency, Firebase internals, and script evaluation for each event. Pretty damn good! Next step there will be to start optimizing depending on the script implementation, cashing compiled scripts, mutli-threading etc.One major up-shot of writing on a script language and re-evaluating the script for each event is the velocity: you don’t have to restart Firebase when you change code, the script is re-evaluated automatically. The round-trip time is cut dramatically!And… You want to see code? Here’ you are, this is the server part of the Hello World tutorial, written in…JavaScript:

Cool, eh?You’ll notice some strange objects above. We bound some helper objects in the evaluation context, “_log” a Firebase Log4j logger, “_support” a tool for string to byte conversion etc, and some other helpful stuff.The JavaScript Hello World can be found here.And tentative documentation here. Have fun!

To be honest, I’m not entirely sure. The Java script support is made to handle both purely evaluated scripts and scripts that can be compiled into Java byte code and executed. I would for example be very surprised if Ruby or Python (JRuby and Jython respectively) didn’t end up compiled in the VM. But I need to look it up :-)Also, as Firebase performs parallel execution on separate areas (called “Tables” in Firebase lingo) we need to look further into the multi-threading support of each script language implementation which will probably tie-in with compilation as well.