Project

go-joker

active

Performance-optimised Clojure-like Lisp interpreter — IR bytecode, WASM backend, 527× faster arithmetic.

Overview

An optimized fork of Joker (Clojure-like Lisp interpreter) for inclusion in gi, a self-hosted coding agent. Four execution tiers — WASM native via wazero JIT, typed IR with zero-boxing, boxed IR for collections, and tree-walker for full Clojure semantics — selected automatically per expression. Mandelbrot runs ~4200× faster than upstream; general Clojure code 10–500× faster.

How it works

The compiler analyses each expression and emits to the fastest viable tier: pure numeric loops compile to WASM bytecode executed by wazero's JIT (~0.2ms), primitive/string/cursor loops use a typed IR stack with zero boxing (~2–8ms), collection-heavy code uses a boxed IR interpreter (~10–40ms), and everything else falls through to the tree-walker for full macro/special-form/I/O support. Generic tail-call optimization, transient vectors/maps, and a native StringCursor type round out the runtime.

Features
4-tier execution

WASM → Typed IR → Boxed IR → Tree-walker — automatic tier selection per expression.

🧮
WASM/wazero JIT

Pure integer/float loops compile to native code via wazero. ~0.2ms for Mandelbrot.

📦
Typed IR (zero-boxing)

Primitive, string, and cursor loops on an irValue stack — no interface{} boxing overhead.

🗃
Transient vectors and maps

O(1) append/assoc for builder patterns — auto-promoted from persistent collections.

🔬
Runtime introspection

disassemble, analyze, wasm-diagnostic, escape-analysis, profile, benchmark, mem-stats, gc — all from Joker scripts.

🎨
Additional namespaces

joker.imaging (image processing), joker.svg (SVG generation + raster), joker.pdf (PDF documents).

Architecture
Clojure Source s-expressions Reader + Parser AST generation IR Compiler tier selection + TCO WASM / wazero native JIT ~0.2ms Typed IR zero-boxing ~2–8ms Boxed IR collections ~10–40ms Tree-walker full Clojure semantics Result value / side-effect 4-tier execution: WASM → Typed IR → Boxed IR → Tree-walker