Moddable Tech Presentation to TC-39

In May of 2017, Moddable Tech presented our XS JavaScript engine to at the Ecma TC-39 meeting at Google New York. We were graciously invited by Brendan Eich, the creator of JavaScript, to share our work applying JavaScript to extremely resource constrained embedded hardware. Brendan believed it would be valuable for the committee to see how the use of JavaScript was expanding far beyond its original web focus. As a result of our presentation and attendance at the meeting, Moddable Tech joined TC-39 to advocate for maintaining the ability to run JavaScript well on resource constrained hardware.

Our presentation was divided into two parts. There were a set of demonstrations to show just how much can be done with JavaScript on an embedded device. This was paired with a talk on the evolution, design, and implementation of the XS engine itself. The talk on XS was given by Patrick Soquet, the guiding force behind XS. It is an excellent introduction to XS for anyone interested in learning how Moddable delivers near full JavaScript language conformance on remarkably constrained devices. We've posted Patrick's full talk, including Patrick's illustrations and diagrams, as it was presented.

The demonstrations of XS were given by me. The following sections provide a summary of the demonstrations. If you have never used XS on embedded hardware, read on. You may be surprised at what is possible.

Note: Patrick and I represented the Moddable Tech team. The work we presented is the work of the entire team.

Demonstration hardware Two of the three demonstrations ran on an ESP8266 microcontroller from Espressif based on an Xtensa CPU at 80 MHz, has 45 KB of available RAM (beyond what is used by the RTOS), 1 MB of available flash storage for code (including the RTOS), and Wi-Fi. We like the ESP8266 because it is readily available and inexpensive (about $2 in volume). There is nothing very unique about the ESP8266 microcontroller, and the XS engine runs with equal efficiency on many other microcontrollers.

The remaining demonstration uses a Thunderboard Sense from Silicon Labs powered by a Gecko microcontroller that runs an ARM Cortex M4 CPU at 40 MHz, with 32 KB of RAM (total), and 256 KB of flash storage.

Demo 1 -- HTTP and TLS The first demonstration, running on the ESP8266, shows communication with the PubNub realtime publish and subscribe API, combining JSON messaging over HTTPS using TLS 3.1 over Wi-Fi. The application is written in JavaScript as is the HTTP client and the bulk of the TLS implementation. Additionally, the demonstration runs attached to xsbug, the XS source level debugger, over USB allowing operation of the scripts to be paused, variables to be inspected, and code to be single stepped. With the full device firmware, XS engine, HTTP stack, TLS stack, and debugging support the device still has over 128 KB of free ROM.

The PubNub service is used for this demonstration because it is a poplar publicly available commercial service intended for use by IoT products. Its use here shows that low cost microcontrollers like the ESP8266 is able to communicate using modern, standard, secure network protocols and services.

Demo 2 -- Sensor hub The second demonstration, this one on the Thunderboard Sense, is an interactive sensor hub connected to a low power display operating on a coin cell battery. The six sensors are sound level, accelerometer, light, humidity, temperature, and barometric pressure. Each sensor is displayed on a separate screen that shows both the sensor reading and an animated graphical representation of the value. The user cycles through sensor screens using physical push buttons. With only 256 KB to store the device firmware, XS virtual machine, scripts, and graphical assets just a few kilobytes of flash storage remains free.

The purpose of this demonstration is to show the feasibility of using JavaScript to build energy efficient interactive user interfaces that run on battery powered devices while interacting with a variety of sensors.

Demo 3 -- Web Workers The third demonstration, again running on the ESP8266, shows a subset of the HTML5 Web Workers API implemented on the XS engine. The main machine spawns four simultaneous workers, each sending several messages, at which point the worker exits and a new one is spawned. The 45 KB of available RAM on the device is able to hold five simultaneous JavaScript virtual machines (main machine and four worker machines), each using about 8 KB. The demonstration spawns 38 virtual machines per second, including messages exchanged with the main virtual machine.

The purpose of this demonstration is to show that a single JavaScript virtual machine can be quite small, and that creating a new virtual machine is fast enough, just a few milliseconds, that it can be performed on-demand. The ability to have several virtual machines or short-lived virtual machines has advantages for security and stability by isolating the access and lifetime of scripts.