TinyGo notes
Jennifer ships as two binaries built from the same source:
jennifer- default, built with the standard Go toolchain. Full host-feature surface: file I/O,os/exec, network stack.jennifer-tiny- constrained variant, built with TinyGo. Smaller binary, embeddable; the stock build ships withoutos/execor a network stack (a build choice, not a hard TinyGo limit - see TinyGo restrictions below).
make build produces both. Use make build-go or make build-tinygo for just one; both regenerate the version file before compiling.
The language is written to stay TinyGo-clean even though the default binary is standard-Go. CI builds jennifer-tiny, so a change that breaks TinyGo compatibility fails there. Constraints:
- No
reflect. Tagged-unionValueinstead of interfaces with type assertions in hot paths; the runtime imports noreflectat all. In particular TinyGo'sreflect.Selectis an unimplemented stub that panics, so the multi-way waits (task.waitAny/waitAnyTimeout,channel.select) use a register-then-poll wait set instead (see the interpreter page). A new reflect use needs justification and a TinyGo run. - Crypto randomness needs
/dev/urandom. TinyGo'scrypto/randon Linux reads/dev/urandom(the standard Go build uses thegetrandomsystem call, which needs no device node). On a minimal container or embedded image without it,crypto.randBytes/randInt/encrypt/mtweiKeygenanduuid.v4/v7raise a catchablesecure random source unavailableerror - never weak bytes. Provide the device (or bind-mount the host's) wherejennifer-tinyneeds randomness;hashandmath.randare unaffected. - Floating-point results can differ in the last ulp. TinyGo lowers
math.Log/Exp/Sqrt/Truncto LLVM intrinsics backed by its bundled C libm, and its LLVM codegen does not always match the standard Go compiler bit for bit, so most transcendental functions (log,exp, trig,erf,lgamma,pow, ...) can disagree withjenniferin the final bit. Neither binary is wrong; sometimes the TinyGo value is the correctly rounded one (log(81, 3)is4.0there and4.000000000000001onjennifer). Golden examples therefore print such results at a fixed precision (%f|prec=N) rather than the shortest round-trip%vform. - No
text/template. Not needed yet; would drag in fragile runtime paths under TinyGo. - No
encoding/jsonfor in-binary serialization. The reflect-based marshaler is fragile under TinyGo, so the AST JSON emitter is hand-rolled (see CLI > Inspection). - Goroutines are allowed (used for
spawn), but need-stack-size=4mbunder TinyGo - see the goroutine-stack note below. - No
-ldflags "-X package.var=value". TinyGo before 0.43.0 silently ignores the-Xdirective, and 0.41.1 is still a supported (CI-tested) toolchain. Use the codegen path (scripts/gen-version.sh->internal/version/version_gen.go) for build-time string injection. See CLI > Version injection. - No hard dependencies on a hosted runtime.
jennifer-tinytargets embedded systems, minimal containers, and small-footprint scripting hosts where ambient stdin, dynamic linking, and a full hosted runtime are not guaranteed. testingruns under regulargo test. TinyGo'stestingsupport is partial; we develop and verify withgo test ./....
Verify both builds after non-trivial changes:
make build
./jennifer run examples/hello.j # default (standard Go); full host features
./jennifer-tiny run examples/hello.j # constrained (TinyGo); no os/exec, no netTinyGo restrictions
Some standard-library features depend on TinyGo runtime support that isn't there today. Calls into them from jennifer-tiny raise a Jennifer-level error pointing at the default jennifer binary, which supports the full surface.
| Library | Affected names | What happens on jennifer-tiny |
|---|---|---|
os | os.run, os.spawn (so os.wait / os.poll / os.kill / os.release have no process to act on) | Runtime error pointing at the default jennifer binary. The os/exec subprocess surface: unimplemented in TinyGo on host targets, and absent by nature on embedded / WASM. Not the same "recompile" story as net - see the note below. |
net | Every entry point (TCP, UDP, DNS) | Runtime error pointing at the default jennifer binary. Our stock jennifer-tiny registers no netdev driver, so net is stubbed. Build-tag split: netlib_tinygo.go returns friendly errors. Not a hard TinyGo limit - see the note below. |
httpd | Every entry point (listen, accept, respond, ...) | Runtime error pointing at the default jennifer binary. The HTTP/1.1 server engine is over Go net/http, so it is stubbed for the same reason as net (no netdev driver): httpdlib_tinygo.go returns friendly errors, and a rebuild with a network stack restores it. |
term | Every entry point (makeRaw, restore, size, readByte, readByteTimeout) | Runtime error pointing at the default jennifer binary. Terminal control needs golang.org/x/term (which the tiny build excludes) and a controlling TTY (which a minimal / embedded target may not have). Build-tag split like net: termlib_tinygo.go returns friendly errors. A timed read could not be supported here anyway: under the cooperative scheduler a read blocked on stdin stops every goroutine, timers included, so the shared stdin buffer (internal/stdinbuf) has no pump goroutine on this build and the reading call fills it inline. |
serial | Every entry point (open, read, write, ...) | Runtime error pointing at the default jennifer binary on Linux. Serial-port termios I/O is a Linux /dev + ioctl feature over golang.org/x/sys/unix, which the tiny build does not carry. Build-tag split linux && !tinygo (real) / else (stub). |
spi | Every entry point (open, configure, transfer, close) | Runtime error pointing at the default jennifer binary on Linux. SPI_IOC_MESSAGE ioctl; same build-tag split as serial. |
i2c | Every entry point (open, read, write, readReg, ...) | Runtime error pointing at the default jennifer binary on Linux. I2C_SLAVE ioctl; same build-tag split as serial. |
gpio | Every entry point (setup, read, write, release, chip) | Runtime error pointing at the default jennifer binary on Linux. The /dev/gpiochipN GPIO v2 line ioctls; same build-tag split as serial. (The sysfs-backed gpio module is the portable default and runs on both binaries.) |
sql | Every entry point (open, query, exec, ...) | Runtime error pointing at the default jennifer binary. The MySQL / Postgres drivers are heavyweight dependency trees that TinyGo does not compile, so sqllib_tiny.go stubs the whole surface (they are unreachable on stock jennifer-tiny anyway - no network stack). Build-tag split like net: sqllib_std.go (!tinygo) imports the drivers, sqllib_tiny.go (tinygo) returns friendly errors. |
crypto | Only the RSA / ECDSA / ML-KEM algorithm names ("rsa-pkcs1-*", "rsa-pss-*", "ecdsa-sha*", "rsa2048".. / "p256".. in keypair / publicKey, "rsa-oaep-*" in wrap / unwrap, "mlkem768"), plus jwkPublic / jwkToPem / csr | Runtime error naming the algorithm and pointing at the default jennifer binary. These pull in crypto/rsa, crypto/ecdsa, crypto/x509 (PEM parsing / CSR), and crypto/mlkem, which are off the TinyGo build; cryptolib_asym_tiny.go / cryptolib_acme_tiny.go / cryptolib_pqc_tiny.go stub them. The rest of crypto - random, deriveKey, hashPassword / verifyPassword, AES-GCM, ChaCha20-Poly1305 and the AES block modes, Ed25519, X25519 (crypto/ecdh builds under TinyGo), and the mtwei* EC-SRP functions - runs on both binaries. (So JWT's HS* / EdDSA work on jennifer-tiny but RS* / PS* / ES* do not, and acme needs the default binary.) |
net on TinyGo is a build choice, not a hard limit
The "no network" state is a property of the stock jennifer-tiny build, not of TinyGo itself. TinyGo compiles most of net.Dial / net.Listen; what it does not do on a default target is register a netdev driver at runtime (the pluggable network device interface its net package dials through), and our stock build ships none - so we compile the tinygo-tagged netlib_tinygo.go stub that returns a friendly error instead of failing cryptically deep in Go's net.
Anyone who needs networking on the tiny binary can restore it by rebuilding with a network stack: target (or link in) a registered netdev driver - or a net-capable target such as one exposing a host socket layer - and drop the tinygo build tag on net so the real implementation compiles in. With a network stack present, net and every net-backed module (smtp, pop, imap, redis, resque, memcache, s3, ...) run on jennifer-tiny too. So read "needs the default jennifer binary" as "needs a build that includes a network stack" - the stock jennifer has one, the stock jennifer-tiny does not. (UDP is the one thinner spot: net.ListenPacket is not part of TinyGo's surface today, so a rebuild covers TCP / DNS more readily than UDP.)
os/exec on TinyGo is a platform limit, not a switch
The os restriction is narrower than it looks: it is only the os/exec subprocess surface - os.run / os.spawn / os.wait / os.poll / os.kill / os.release. Everything else in os works on both binaries (see below).
Do not read the net note above as applying here. net needs a pluggable driver you can supply; os/exec needs a whole host operating system with a process model - fork/exec, a process table, executables on a filesystem. There is no component to link in. Two cases:
- Host-OS TinyGo target (Linux / macOS / Windows): a TinyGo standard-library maturity gap - the
os/execfork/exec path is not implemented yet. If TinyGo upstream adds it, a host-targetedjennifer-tinycould gainos.run/os.spawn; that is upstream work, not a rebuild switch on our side. - Embedded / bare-metal / WASM / WASI targets (what
jennifer-tinyexists for): there is no process model - nothing to fork, no other programs, noexecsyscall. The subprocess surface is a hard platform limit there and stays unavailable permanently.
This fits the deployment target: minimal containers and embedded scripting hosts generally should not shell out to external processes (no shell, no other executables).
The constants and the env / argv helpers in os (os.PLATFORM, os.ARCH, os.EOL, os.DIRSEP, os.PATHSEP, os.ARGS, os.argsBytes, os.getEnv, os.getEnvBytes) work on both binaries. os.isTerminal works on both too, but jennifer-tiny has no golang.org/x/term, so it falls back to the character-device mode bit (isterminal_tinygo.go): right for a pty, a pipe, and a file redirect, wrong only for a non-terminal character device such as /dev/null. Every shipped library except the stubbed ones above (net, httpd, term, serial, spi, i2c, gpio, sql), the os/exec slice of os, and the RSA / ECDSA / ML-KEM slice of crypto has full TinyGo support on both binaries - io, convert, math, stats, linalg, ml, strings, lists, maps, binary, path, meta, time, hash, crc, crypto, decimal, compress, images, archive, asn1, encoding, json, kv, toml, xml, yaml, intl, task, channel, fs, regex, testing, and uuid. Two carry a third-party dependency: yaml (gopkg.in/yaml.v3, verified to build and run under TinyGo 0.41.1 and 0.43.0) and crypto (golang.org/x/crypto, which builds for both binaries); every other library is Go standard library or hand-rolled.
Development subcommands are default-binary only. jennifer-tiny is a run-only interpreter: run and repl execute Jennifer source, but the development subcommands tokens, ast, fmt, lint, profile, and test are build-tag-excluded (cmd/jennifer/devtools_tinygo.go) and return a friendly error pointing at the default jennifer binary. They pull in lexer-dump, AST-JSON, formatter, and lint machinery that a minimal-footprint embedding has no use for; build the standard-Go jennifer binary for development work.
jennifer-tiny-dev, for CI. The exclusion is for size, not compatibility: the subcommands are TinyGo-clean Go. The tinygo_devtools build tag compiles them back in (the real files are //go:build !tinygo || tinygo_devtools, the stubs tinygo && !tinygo_devtools), and jennifer-tiny-dev is that build:
make build-tinygo-dev # or, as the images do:
tinygo build -scheduler=tasks -stack-size=4mb -no-debug -tags tinygo_devtools \
-o jennifer-tiny-dev ./cmd/jenniferIt takes exactly jennifer-tiny's flags, so the runtime is the same: the same 4 MB stack, the same call-depth and nesting caps (internal/limits), the same stubbed libraries. Only the subcommands differ. Its use is running a deck's test overlays on the constrained runtime (jennifer-tiny-dev test src/x_test.j), which the deck CI's jennifer-tiny job does, and profiling a TinyGo-only issue in situ (jennifer-tiny-dev profile). serve stays stubbed (no network stack), and test --isolated is refused (it starts a process per test, and TinyGo has no os/exec). It costs 0.5 to 0.8 MB (+8 to 14%) over jennifer-tiny (see Binary size). The container images carry it at /usr/bin/jennifer-tiny-dev; the release archives and the distribution packages do not.
TinyGo goroutine stack
Jennifer's tree-walking evaluator wraps each Jennifer-level call in many Go-stack frames (execBlock + evalCall + evalExpr + ...), so even a modest-depth recursion (fib 23) exceeds TinyGo's default goroutine stack of ~8KB and segfaults. The Makefile passes -stack-size=4mb to tinygo build for jennifer-tiny so it can run recursive spawn bodies (and the parallel section of examples/benchmark.j). The default jennifer binary doesn't need this - Go's goroutine stacks grow automatically.
That fixed 4 MB stack also sets a hard ceiling on how deeply the tree-walker can recurse over nested data: a deeply-nested source literal, or a deeply-nested json / toml / xml / asn1 document, drives one recursive descent per level, and the interpreter has no recover(), so an overflow is a fatal crash rather than a catchable error. Every recursive-descent parser (the language parser and the four hand-rolled decoders) therefore enforces a shared nesting cap, internal/limits.MaxNestingDepth. It is build-tag split: 1000 on the default binary (growable stack), and 64 on jennifer-tiny, well below the depth where the heaviest shape (a nested map literal) overflows the stack (on a 2 MB stack it survived 96 levels and segfaulted near 128; 4 MB roughly doubles that floor). Exceeding the cap is a positioned parse error / catchable decode error on both binaries. yaml keeps its own pre-parse guard (it is backed by a Go dependency, not a hand-rolled descent). The same cap bounds values where they are built: a literal or an index, field or append write that would nest past it throws a catchable "limit", so every walk over a value (copy, ==, display, the encoders) stays bounded on both binaries.
The same 4 MB ceiling limits how deep the tree-walker can recurse at runtime. Function calls are not the only thing that stacks Go frames - nested blocks and nested expression operands do too - so internal/limits.MaxCallDepth counts all three: a per-call-chain counter (CallChain, fresh at each goroutine root) bumped on every function entry (evalCall and the cross-boundary dispatch meta.call / meta.callMain), block entry (execBlock), and expression-operand descent (an inline bump around each operand in evalBinary / evalUnary / evalLogical - inline, since a non-inlined helper there cost tight numeric loops about a fifth of their speed). Each fresh counter is padded to its own cache lines (newDepthCounter): it is written on every operand, so two spawn workers' counters sharing a line made parallel loops contend for it. The cap thus bounds real Go-stack depth however a frame mixes recursion with nesting; a call-only count let ~10 nested blocks, or a call wrapped in many parens, overflow below it. The check runs only at the call sites - block and expression nesting alone are bounded by the parser's MaxNestingDepth caps, so the counter only runs away through a checked call. A simple recursion spends about 3 units per level. Build-tag split: 10000 on the default binary (about 3300 simple levels, about 70 MB RSS at the cap), 400 on jennifer-tiny (about 133 simple levels). On jennifer-tiny a call check also measures the stack itself (stackguard_tiny.go): a chain that has used more than 3 MB of the 4 MB stack fails the same way, since TinyGo's tree-walker frames are large enough for a heavy body to pass 4 MB well below 400 units. With the unit cap raised to 1000 for the measurement, the stack guard stopped every shape tried first and cleanly: simple recursion at 130 to 150 levels, a heavy body at 27, and a 62-deep map literal or 60-deep list literal plus parens at the stack edge. Exceeding either is a catchable "call stack too deep" error (kind "limit") instead of a segfault; each spawn body gets its own counter. That bounds the stack, not the heap: the heap held by per-frame value copies along a call chain has its own catchable cap, limits.MaxCopyChainBytes (64 MiB on jennifer-tiny, 1 GiB on the default binary).
The parser has the matching front-end guard. Flat operator chains (a+a+...) and prefix runs (---...) are parsed by loops / self-recursion that do not re-enter the general expression entry, so without a cap they build an AST far deeper than MaxNestingDepth for a later walk to overflow on. Each binary-loop iteration and prefix recursion counts against exprDepth (deepenExpr), so an over-long chain is a positioned parse error.
TinyGo scheduler. jennifer-tiny pins the cooperative single-thread scheduler (-scheduler=tasks in the Makefile). spawn works (semantics, loud-fail, registry), but every goroutine shares one OS thread, so it gives concurrency without multi-core parallelism: parallel speedups stay close to 1.0, and -stack-size=4mb reliably covers recursive spawn bodies. TinyGo's threads scheduler gives multi-core speedups but segfaults on recursive spawn bodies, because -stack-size does not govern OS-thread stacks. The default jennifer binary gets multi-core parallelism from Go's scheduler.
Many live tasks are slow to start. With 4 MB stacks under TinyGo's default collector (gc.boehm), starting N goroutines that are all alive at once costs time close to proportional to N squared: about 1 s for 50, 4 s for 100, 12 s for 200 in a plain Go reproduction with no Jennifer code in it (the standard Go toolchain: under a millisecond). Each live task also holds about 4 MB. A second batch of the same size in the same process is fast, and the cost scales with the stack size the same way (at 200 goroutines, 1 MB stacks take about 0.7 s), so it looks like a collection per new stack that scans every live stack. -gc=conservative and -gc=precise are linear but run out of memory at 400 live 4 MB stacks, where Boehm completes at about 1.7 GB, and precise makes copy-heavy code about three times slower, so the Makefile keeps the default. A smaller stack is not an option either (see the next paragraph). Programs for jennifer-tiny should keep the number of live tasks small - a worker pool fed by a channel, or spawn-and-wait - which is what the spawn capture benchmark row does; the user-facing note is in concurrency.
A stack overflow is not always a crash. TinyGo does not reliably trap a goroutine that runs past its fixed stack: built with -stack-size=1mb, a recursion that builds a map literal per call (about 100 KB of Go stack per Jennifer call level) survived 9 levels, and from 10 levels on it sometimes panicked and sometimes returned bogus runtime errors ("cannot initialize map of string ...", "operator - requires numeric ...") from corrupted values. The 4 MB stack, with limits.MaxCallDepth (400), the 3 MB stack-bytes guard and limits.MaxNestingDepth (64) below its overflow floor, is all that stands between an over-deep program and silent corruption. Never lower -stack-size without re-measuring the deepest recursion and nesting that still survive, and lowering both caps to match.
A new TinyGo runtime gap gets a row in the restrictions table and the same friendly-error stub.
Binary size
jennifer-tiny is the smaller build (it targets minimal-footprint deployments). Sizes from make build on linux/amd64 (Go 1.26.5, TinyGo 0.41.1, unstripped). The absolute numbers move with toolchain version and platform; the ratio is the stable part.
| Binary | Size |
|---|---|
jennifer | ~23.3 MB (23,253,990 bytes) |
jennifer-tiny | ~10.4 MB (10,385,072 bytes) |
jennifer-tiny comes in at ~45% of the default binary (just under half the size). Most of that gap is TinyGo's smaller runtime versus the standard Go runtime, plus the network-, os/exec-, and database-driver-backed libraries the tiny build stubs out; the run-only trim (excluding the tokens / ast / fmt / lint / profile / test development subcommands) shaves an incremental slice on top. The gap has widened as the default binary grew (the database drivers and crypto surface land only on the standard build), so the ratio drifts with each library the tiny build stubs.
These are unstripped make build (dev) sizes. Release builds strip: the Go binary adds -trimpath -ldflags "-s -w" (down to ~16.0 MB, a ~31% cut) and the TinyGo binary adds -no-debug (down to ~4.5 MB, a ~57% cut); dev builds keep symbols for debugging.
jennifer-tiny-dev (the tinygo_devtools build, with the release -no-debug) against jennifer-tiny from the same tree, linux/amd64:
| Toolchain | jennifer-tiny | jennifer-tiny-dev | Added |
|---|---|---|---|
| Go 1.26.3, TinyGo 0.41.1 (the image) | 5,483,256 bytes | 5,944,552 bytes | ~0.46 MB (+8.4%) |
| Go 1.27.3, TinyGo 0.44.0 | 5,835,848 bytes | 6,632,160 bytes | ~0.80 MB (+13.6%) |
Benchmarks
Single-binary throughput - jennifer (Go) vs jennifer-tiny (TinyGo) across the serial and parallel workloads of examples/benchmark.j, plus the memory / page-fault trade - lives in its own doc: benchmark.md.