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.

Jack sparrow said...

Thank you for sharing such a great information.Its really nice and informative.hope more posts from you. I also want to share some information recently i have gone through and i had find the one of the best mulesoft videos

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.

stevesmith24644 said...

I have scrutinized your blog its engaging and imperative. I like your blog.
custom application development services
Software development company
software application development company
offshore software development company
custom software development company

Unknown said...

Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
mulesoft online training
best mulesoft online training
top mulesoft online training

Python said...

Thanks for sharing all the information with us all.
Data Science Online Training
Python Online Training
Salesforce Online Training

aveesha said...

Great article! It is really helpful for my research. Do post and share more such wonderful content and keep updating.
Informatica Cloud Training
SAP Hybris Training
AWS‌ ‌Data‌ ‌Engineering‌ Training

Tarun said...

Nice article. Thank you for sharing.
Mulesoft Training

aveesha said...

Great post ! This was actually what i was looking for and i am glad to came here!
PingFederate Training
MuleSoft Training

kriti said...

Thank you for sharing such a good information. Very informative and effective post. Keep it up!
Training for devops

Apoorva said...

Nice article, thanks for sharing informative post.
power bi course

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

Pankaj Nagla said...

Thankyou for sharing the information. Website is so easy to use – I am impressed with it.
Devops Course

Tarun said...

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

Nikhil Sharma said...

I read your post. It is very informative ad helpful to me. I admire the message valuable information you provided in your article.
power bi training

manish said...

Post is very much informative and content is so much convincing that I look for more in the future.
DevOps Certification is very helpful in the current market trend.

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

Sim Speaks said...

This article has alot of valuable information. Great work. Thank you for sharing this with us. Learn more about machine learning course here and build your Career.

rebu sarkar said...

This is a nice post valuable sentences,So much to learn.splunk training thank you for sharing


Nice article. This has a lot of information. Thank you. Also learn about python course and other courses to gain more knowledge and build your career.

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)

Ankita Garg said...

Nice content, so much convincing and easy to grasp. Thank you for sharing.sap analytics cloud training

Shankar267 said...

Thank you! I learn lots of information from your post and I like your written style. I hope more unique post from your blog...

IFB Washing Machine Service Center in Hyderabad

Blue Star AC Service Center in Hyderabad

Movers and packers in Dubai, Movers in Dubai said...

The Move Me Professional Movers and Packers in Dubai. Contact us today for professional movers in Dubai. Make your move stress-free with The Move Me movers and packers in Dubai, UAE.
house movers packers dubai

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

Peter Johnson said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end. best micronutrients for plants

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