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. Five execution tiers — native integer codegen, 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; fib(35) in 0.5s via native codegen.

How it works

The compiler analyses each expression and emits to the fastest viable tier: pure-integer recursive functions compile to native Go closures (53× faster, zero boxing), 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.

Features
Native integer codegen

Pure-integer recursive defn bodies compile to fixed-arity native Go closures. fib(35) in 0.5s (53× faster).

🧮
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.

🌐
Web runtime

Ring-style HTTP server with WebSocket and SSE/streaming extensions. Bottle-style router with path params, middleware, and CORS.

🔬
Clojure parity surface

Protocols, records, hierarchies, tagged literals, sorted collections, atom watchers, chunked seqs, unchecked arithmetic.

🎨
Additional namespaces

joker.imaging (image processing), joker.svg (SVG + raster), joker.pdf (PDF), joker.random, joker.log, joker.http, joker.http.router.

🔧
Runtime introspection

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

📓
Web notebooks

Mathematica-style EDN notebooks with Observable-style dependency metadata. Local browser UI (CodeMirror + ECharts + Mermaid, no CDN), headless execution, Markdown export, and self-contained inline outputs for agent/debug reports.

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
Posts
Notes for May 3-10