Skip to content

KryonOS Javascript Runtime

Haris edited this page Jun 20, 2026 · 1 revision

KryonOS JavaScript Runtime

The KryonOS JavaScript Runtime is a tailored implementation designed specifically to bring high-level JS execution to the RAM-constrained ESP32.

The Duktape Engine

KryonOS uses the Duktape 2.x

Memory Constraints & Optimization

The ESP32-WROOM has approximately 520KB of total SRAM. However, after the Wi-Fi stack, the LittleFS buffers, and the C++ OS Kernel load, there is typically only around 90KB of usable free RAM left for the JS Engine.

Optimization Strategies used in KryonOS:

  1. Garbage Collection Forcing: Duktape uses Mark-and-Sweep. If memory gets too fragmented, large objects fail to allocate. In KryonOS, whenever an app calls System.delay(), the kernel intercepts this and uses the idle time to manually trigger a garbage collection sweep, keeping the heap healthy.
  2. JSON Streaming vs. Parsing: When the system reads app.json metadata to populate the App Store or Launcher, it specifically avoids loading the entire JSON structure into the Duktape RAM at once, preventing "Out of RAM" spikes.

Sliced Double-Buffering

One of the most complex challenges in embedded graphics is rendering 3D shapes or complex UI without flickering. Usually, this is solved by "Double Buffering" (drawing to an invisible RAM canvas, then pushing it to the screen instantly).

However, a full 240x320 16-bit color canvas requires 153.6 KB of RAM—which is more than the ESP32 has available!

The Solution

KryonOS implements Sliced Double-Buffering (as seen in the Cube3D game). Instead of allocating a full-screen canvas, the engine allocates a tiny horizontal "slice" (e.g., 240x32 pixels, taking only ~15KB). The Javascript app renders the entire 3D frame, but the C++ engine clips the rendering so only the pixels inside the current slice are drawn to the buffer. The slice is then pushed to the screen via DMA, the buffer is moved down, and the frame is drawn again.

This technique requires the JS Engine to re-evaluate the physics/math multiple times per frame, trading CPU cycles for strict RAM adherence, resulting in perfectly tear-free, smooth graphics without crashing the OS.

Clone this wiki locally