InsightsCompiled to WebAssembly

Brainfuck compiled to WebAssembly

Every program on this site runs in your browser as WebAssembly. The film shows brnfck-qwen2.5-1.5b, Qwen2.5-1.5B-Instruct written out as one brainfuck program, answering a question.

brnfck-qwen2.5-1.5b: 11,430,468,880 characters of brainfuck, folded into one square, with its five parts named. Then its engine is compiled to WebAssembly and answers “What is 12 + 30?” in 460,967,591,585 brainfuck steps. The film is sped up: in a desktop browser the program is ready in about two and a half minutes and prints a word piece about every 9 seconds.

Two parts of one program

The first 11,334,697,744 characters only write numbers into memory: the weights of the model. The runtime recognises them and writes the numbers while the file downloads, instead of running them one command at a time.

The last 95,771,136 characters are the engine. They read the question, do the sums and print the answer. The runtime turns them into 346,359 operations, with runs of the same command folded into one and loops that only move a value turned into a multiplication, and those into one WebAssembly module of 16,376,367 bytes with 137 functions.

Compiled against interpreted

The same file, brnfck-smollm2-135m (SmolLM2-135M), asked “Hello” on one computer. Both printed the same answer, byte for byte: “Hello! How can I help you today?”

Run byTime
bf2run, a brainfuck interpreter in C (rdebath/Brainfuck)10 min 22.0 s
the brnfck runtime, compiled to WebAssembly (Node.js)24.8 s

Compiled, it is about 25 times faster.

More than 4 GB of memory

The tape of brnfck-qwen2.5-1.5b is 1,827,870,014 cells of 4 bytes: 7,311,480,056 bytes, or 111,597 pages of 64 KiB. Memory with 32-bit addresses ends at 4 GiB, so for this program the runtime asks for 64-bit memory (memory64, part of WebAssembly 3.0). The tape of brnfck-smollm2-135m is 188,012,789 cells and fits in 32-bit memory. That is why brnfck-qwen2.5-1.5b needs a current desktop browser and about 8 GB of free memory.

Try it