← All finds

Find No. 009 · Oct 20, 2026 · 2 min read

Plain JavaScript compiled into neural nets

Handwired turns plain JavaScript into a neural net. No training, exact, still differentiable.

chenglou/handwired
Screenshot of handwired

Chenglou's handwired takes ordinary JavaScript and turns it into a neural net. There's no training step. The weights aren't learned, they're derived from your code, so the net computes exactly what the program computes. It also stays fully differentiable. Normally you have to pick between code you can reason about and a model you can backprop through. This project is an attempt to get both from the same artifact.

How it works

A program is mostly if-else, loops and state. Handwired rewrites those into matrix multiplication plus ReLU-style activations over floats. The README walks through a small example:

const a = 5
const result = (a > 4) ? 10 : 12

becomes plain arithmetic:

const above4 = Math.max(0, a - 4) - Math.max(0, a - 5)
const result = above4 * 10 + (1 - above4) * 12

Math.max(0, x) is ReLU. For an integer a, above4 is 1 when a > 4 and 0 otherwise. Both branches get computed and the flag picks one. Handwired then collects all the adds, multiplies and ReLUs into one giant matmul and runs it in JS or on WebGPU.

Everything comes down to two primitives, so the whole program stays differentiable. The weights are written by hand, not trained. And standard GPU tricks like fusion, sparsity and reordering have very little to work around.

Try it

git clone https://github.com/chenglou/handwired
cd handwired
bun install
bun start

The demos also run live at chenglou.me/handwired, and the README points to docs/, src/ and template/ as starting points.

My take

This is a research toy, and I mean that as a compliment. The core trick is easy to follow. You can check the ternary example by hand in thirty seconds and then see how far the idea stretches. The use cases in the README are the fun part. You could unfreeze the hand-written weights and train them, though the author openly says they don't know what that does yet. You could bolt a frozen program onto a generic net and train the two end to end. Or you could get GPU-level parallelism out of single-threaded JS. The JSON search demo reportedly runs in milliseconds over 100k documents.

There are limits. The README is short. It doesn't say which subset of JavaScript gets compiled or what the performance tradeoffs look like outside the demos. Because both sides of every branch are computed, I'd expect branch-heavy code to get expensive, but that's my guess, not something the README measures. The lab/ folder is described as old experiments, so expect rough edges.

Who should care: people working on differentiable programming, anyone curious how far plain matmuls can go as a compute model, and WebGPU tinkerers. If you want a production compiler, this isn't one. If you want an idea that's worth an afternoon, clone it.