'MicroQuickJS' that can compile and run JavaScript programs for embedded systems running on just 10KB of RAM



Embedded systems used to control home appliances and industrial equipment have limited memory capacity to reduce costs. Recent improvements in hardware performance have made it possible to use scripting languages such as JavaScript and Python as a replacement or supplement to C and C++. Fabrice Bérard , creator of FFmpeg , has now released MicroQuickJS , a JavaScript engine that can run JavaScript even in low-memory environments.

bellard/mquickjs: Public repository of the Micro QuickJS Javascript Engine
https://github.com/bellard/mquickjs/

MicroQuickJS can be built and executed with 10KB of RAM and about 100KB of ROM as a C library. Other requirements include that it only supports a subset of JavaScript, with a specification close to ES5 . Strict mode is required, and error-prone or inefficient JavaScript syntax cannot be used.

This time, we will test in an environment with a GCC compilation environment on AlmaLinux 9. First, clone the mquickjs repository with git.


git clone https://github.com/bellard/mquickjs.git



Go to the mquickjs folder and run 'make'.


cd mquickjs
make



The executable file ' mqjs ' has been created. First, run the test script './mqjs --memory-limit 10k tests/mandelbrot.js', which limits memory usage to 10KB and calculates and plots the Mandelbrot set . A simple fractal diagram was displayed.



In addition to running it from a script, you can also create compiled bytecode to write to ROM.


./mqjs -o mandelbrot.bin tests/mandelbrot.js



It is also possible to execute the bytecode directly.


./mqjs -b mandelbrot.bin



◆Differences from QuickJS
MicroQuickJS is derived from QuickJS , created by Berard, with the following differences:

・Language support
MicroQuickJS: ES5 subset + some extensions
QuickJS: Nearly full ES2023 functionality

・Character code
MicroQuickJS: UTF-8
QuickJS: Internally UTF-16

Garbage collection
MicroQuickJS: Trace type
QuickJS: Reference counting + cycle elimination

MicroQuickJS is optimized for memory efficiency and is an effective JavaScript engine when the latest features and complex control are not required.

Hacker News , a social news site, is discussing MicroQuickJS, including a discussion of Lua vs. JavaScript that begins with, 'If this had been available in 2010, Redis scripts would have been written in JavaScript, not Lua .' They also introduce the MicroQuickJS Code Executor , which allows you to try out MicroQuickJS in your browser.

in Software,   Review, Posted by darkhorse_logmk