NectarJS : compiling JavaScript into Native Binaries for Every Platform

Adrien Thierry
codeburst
Published in
5 min readDec 12, 2017

--

[Project update] Launching a JS compiler : how to deal with strong expectations about NectarJS

Hi, I’m Adrien Thierry, and I am launching an alpha of an important project that I have been working on for a year: NectarJS.

NectarJS is a JavaScript compiler that allows JS developers to do everything, efficiently, with their favorite language.

Since last September, I decided to devote myself to this project by giving up all my other activities.

Here’s the reason why.

The begining

Since I was young, I was always passionate about computers and crazy about efficiency. I love software development and computing technology. I started with Windows 3.1 and DOS when I was 5 years old. I coded in C/C++ some little funny games and tools on Windows 95 and 98 around 7. During high school, I started to learn Ruby, Python, Perl and Java, and I used to play with Metasploit.

After not very exciting studies in science, I decided to stop wasting my time and start my own business in cyber security to work on a variety of exciting side projects.

During a rainy day in November 2016, I was working on one of them, FortressJS, an I/O NodeJS framework focused on speed and security. I’m huge fan of JS because it’s very versatile and perfect for prototyping.

On this particular project I was testing different solutions to package an app with my framework, like Nexe, JXCore or EncloseJS.

I discovered that a lot of developers were searching, as I did, how to package a JS app. Nexe or EncloseJS can’t compile JS; they generate bytecode with V8 engine. Furthermore, they’re not fully compatible with NodeJS. Regarding JXCore, the project was dead.

Aside from packaging, http benchmarks had shown that NodeJS wasn’t as fast as compiled languages. I made many technological tests to see what was the most efficient thing to achieve both packing and efficiency.

I finally found Crystal. Crystal is a Ruby-like compiler, based on LLVM, that is really fast. On http benchmark, it’s clearly faster that NodeJS. 2 solutions were possible for me:

  • Re-code my app in Crystal or Go
  • Try to compile JS

Crystal is fast and awesome, but it’s not fully cross platform. I love Ruby’s syntax, but NodeJS ecosystem is gigantic, and JS is everywhere. Regarding Go, it’s an awesome language and ecosystem, but I’m not as much as a fan as I am of JS.

The second solution seemed crazy to me, but it sounded like a passionate challenge: compiling JS.

Compiling objects with nectarJS

Compiler as a Service

I began creating a compiler for JS. I focused on compiling a few JS instructions on Linux, like math operations and logical instructions. I started with “for loop” and functions. Managing non-type variables was also a bit complicated, but I achieved that with time, tests and a multi-pass algorithm. It was a step by step work, with help from the “Dragon book”.

After two weeks of working hard on this project, I started to bench performances, size and time to compile.

And surprise! Performances were impressive.

Performances with Fibonacci example

It was a good start, but I was only able to compile JS for my Linux computer.

That’s why I began to imagine a CAAS (Compiler As A Service) for JS: writing my app with what I want, and sending it to compile for everything.

Very quickly after I started this project, a lot of crazy ideas came into my mind, including:

  • Better performances for JS
  • Compiling JS to WASM (Web Assembly)
  • Write tiny firmwares for IOT (Arduino for example)
  • Doing everything in JS
  • Compiling an app for every platform, with everything
  • and much more …
NectarJS help menu

After one month, it became more and more time consuming. To continue this exciting project in addition to my other activities, I tried, with some friends, to make a crowdfunding campaign. Even if it seemed crazy, I wanted to develop a strong community network and complete NectarJS with a lot of libraries and debugging tools, by hiring developers to work on it.

However, obviously, without creating a community before launching this crowdfunding campaign, I didn’t achieve my goals. Nevertheless all wasn’t lost ; some people clearly show their deep interest in technology.

I then faced an important decision:

  • To stop NectarJS and continuing my professional activities,
  • or to devote myself to this project.

Once again, I chose the second.

Why ?

Because I am certain that this solution has a future, that tomorrow a JS dev will be able to be nearly as efficient as a native C coder. I also want to do everything to make NectarJS the best tool for JavaScript.

Since September, I have completely stopped my audit and training activities, and I have brought together a team to work on Nectar JS with me.

And it’s working very well.

We have bootstrapped an alpha version with an embeded JS engine that works great on Windows, Linux, WASM and ASM.JS, even if it’s not as fast as we’d like it to be. It already allows users to compile EcmaScript 5, and parts of ES6 and ES7, and we are adding compatible libraries with NodeJS, like FS, Process and HTTP.

Launch a process with NectarJS

About the future

We want to make JS a universal language for coding everything, everywhere. JS is present in every web browser; it’s more and more present in server side with NodeJS, and it is also used for IOT with Espruino. However, each platform has its own specifications. With NectarJS, we want to unify all of these in one solution.

It’s the beginning of a new, fantastic adventure, and you can be a part of it.

To be as fast as possible, we need feedback on NectarJS to improve it. We have a slack where you can subscribe : NectarJS’ Slack

NectarJS’ alpha will be free during the testing phase. You can get your free key here : http://nectar-lang.com/key/

Once done, you can get NectarJS client on github here : https://github.com/seraum/nectarjs

Thank you for your help,

Adrien

--

--