A place to be (re)educated in Newspeak

Thursday, August 23, 2012

Newspeak on Dart

We've wanted to run Newspeak to run in a web browser for a long time - actually, since before the Newspeak project started.  The need for better programming languages for the internet platform has been evident for a while.  In a better world, the Newspeak project would be focused on that from day 1.  

However, this world is suboptimal.  It was only in 2010 that I spent some time sketching out the first version of NS2JS, the Newspeak-to-Javascript compiler. It was a toy, but in 2011, Vassili Bykov managed to bring it to the verge of self hosting. Performance, however, was abysmal.  Having since joined the Dart project and learned more and more about the challenges Javascript poses as a compilation target (or anything else) I guess this really should not have been a surprise.

We were able to reuse a part of that effort this summer when Ryan Macnak came to Google in Mountain View as an intern with the Dart team. His mission: NS2Dart, a Newspeak to Dart compiler. A detailed report is available at

The results are promising, though there is still a long way to go. Despite considerable losses due to impedance mismatches, on the Dart VM, NS2JS comes within a factor of 2 of the Squeak based Newspeak implementation (NS2Squeak). Given that the current version of NS2Squeak is twice the speed it used to be (thanks to Cog)  it looks like performance is tolerable already. And since Dart will get much faster (the numbers in the tech report are already out of date), the future looks bright.

Now, when someone says the future looks bright, you should be getting nervous. So, just sign the dotted line, and then I'll get to the caveats ...

The current version relies on access to Dart VM's embedding API, which means you cannot run it in the browser. Hopefully, over time enough functionality will get added in the way of mixins and mirror builders that the same results can be accomplished in pure Dart. That is not yet certain, but let's retain the uncharacteristically optimistic tone of this post, and assume that does happen.

Since most browsers are likely to run Dart via translation to Javascript for some time, we need to look at the NS-Dart-JS pipeline: compiling Newspeak via NS2Dart, and feeding the result to dart2js (The Dart to Javascript compiler) to obtain Javascript code that runs in any browser.

Early on, NS2Dart could run on top of dart2js (by cheating on things like dynamic mixin application) and results were much better than with NS2JS. This is to be expected: dart2js does the heavy lifting for us.  The dart2js compiler already has 4-5 times as much code as NS2JS and is being developed by a very skilled team who understand JS performance inside and out.  Furthermore, it has taken a while to get to this point and performance work is by no means done yet.  So I don't feel too bad about our efforts on NS2JS.

Nevertheless, there is a lot of uncertainty over how well Newspeak can run on top of current Javascript implementations. A key problem area are non-local returns (NLRs). These are essential for user defined control constructs. They are not supported in Dart precisely because it is not clear how efficiently they can be implemented on top of Javascript.

Mirror support on NS2Dart is very partial - the mapping to Dart's mirrors is pretty clean so far, but Dart mirrors are a work in progress, and so far only cover introspection. 

Then there remains the small matter of the UI. I'd love to see the Hopscotch GUI on the browser, but that is a ton of work as well.  We'll see what UI solutions shape up in that space - we can always just call out to whatever UI Dart exposes (Ryan also implemented a Dart Alien API). So altogether, it might be a tad premature to declare victory, but we are making progress.

The dream remains to get a fully functioning system, Hopscotch, IDE and all that works well in the browser. However, I can imagine that many applications could get by with a lot less.  

The details are in Ryan's report and the code is in the Newspeak repo, where you can also get the latest Newspeak images with which to view it (I recommend you do that rather than use the old release; a new release will be out very soon). Thanks are due  to Vassili (whose work on NS2JS made this possible)  and to my colleagues on the Dart team, who graciously supported this effort in various ways, and most of all to Ryan.

Altogether, getting a top quality programming experience on the web requires a major effort.   Dart is beginning to make this possible.


Richard Cole said...

Would browsers supporting a VM be an improvement or are VM all too different to have one VM supporting many languages in the browser?

Gilad Bracha said...

No one has shown a compelling "universal VM". The point of a VM is to raise the level of abstraction (otherwise you can just use the real machine, you don't need a virtual one). The problem is that you have to choose what higher level abstractions to support; if your language fits with those abstractions, all is well, otherwise things work poorly.

Which is not to say that you could not have a better set of primitives than those supported by browsers today. Good support for integers, access to the stack, weak references, concurrency primitives etc. would help a lot. Some of these things are improving with time, some less so.

What we have in practice is a accident of history; it has some valuable flexibility (e.g., dynamic typing) but not always in the right place.

IT said...

I like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting mulesoft online training
servicenow online training
java online training
Tableau online training
ETL Certification

MongoDB Online Training

svrtechnologies said...

I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks mulesoft training online and mulesoft videos.

vishesh paliwal said...

Write Great article. You are such a Great blogger and your website is inspiration for me to start a blog. This article is very helpful for us.DevOps Training

Tarun said...

Nice content, so much convincing and easy to grasp. Thank you for sharing.
power bi certification

Vandana Boro said...

Thanks for your time on putting these all together.Your blog has a lot of valuable information. Really helpful blog.
tableau training

Lokeshkumarraj said...

This is a nice post valuable sentences,So much to learn. professional course

Pankaj Nagla said...

I think this is a very good site and will continue to use it.
Ccsp Certification

Prasanjit's BLOG said...

Nice and valuable words with great information loved it.Thanks uipath training for sending this content.

ravi said...

(nice thanks for shareing good information vist this also)

Shashank said...

Bosch Service Center technicians take care of your Bosch Washing Machine Bosch washing machine customer care is the best and under-budget service center.Whether you have a Bosch top loading washing machine or a top load or Bosch front loading washing machine we will fix it at your doorstep.

Unknown said...

Hi, it's a very nice blog post and useful info. Thanks for sharing and keep posting. I also want to share some information recently I have gone through and I had find the one of the best mulesoft video course. Visit the site - https://mulemasters.in/mulesoft-video-course/

Unknown said...

Hi, it's a very nice blog post and useful info. Thanks for sharing and keep posting.Mulesoft Video Course

laxmicynixit said...

nice information .............!
google cloud data engineer certification

laxmicynixit said...

nice information thanks for sharing......!
google cloud data engineer certification

Davis John said...

Nice thanks for sharing good information.

Are u Looking for Acne Treatment in Hyderabad
Click here: Online Training

Training Medal - One Of The Best WordPress Training Institute In Hyderabad said...
This comment has been removed by the author.
Training Medal - One Of The Best WordPress Training Institute In Hyderabad said...

Nice thanks for sharing good information.

Are u Looking for WordPress Training in Hyderabad
Click here: WordPress Training in Hyderabad

laxmicynixit said...

nice information thanks for sharing.......................!
google cloud data engineer certification

David said...

Nice blog thanks for sharing information if like more visit this site.

If u Interested to learn LNATCoachingOnline

Athenakinderhaus said...

Thank you for sharing such a really admire your post. Your post is great! . Best Montessori Schools in Hyderabad