r/Compilers • • 2d ago

Evie: an interpreted programming language written in Go that keeps pace with C Lua 5.4

[Evie](https://hxkhan.github.io/evie/) is a small dynamic language I built to be embedded in Go programs. Its interpreter compiles the AST once into Go closures, so nothing inspects the tree at run time, and there's no bytecode or JIT.

On an 8-program benchmark suite (geometric mean) it comes out slightly ahead of C Lua 5.4 overall:

Evie 55.7 ms · Lua 5.4 57.5 ms · QuickJS 83.4 ms · Python 3 115.0 ms · V8 without JIT 120.7 ms

What makes it fast:
• Small values: every value is 16 bytes, with numbers stored inline and never allocated.
• Specialised operators: each operator gets a generated closure for every operand shape, such as local + constant or local + local, so the hot paths skip type dispatch.
• Dictionaries like CPython's: objects keep insertion order in a compact table, with one hash per lookup.

Lua still wins numeric loops and big dictionaries. Evie wins calls, classes and strings.

On AI use: I wrote the majority of the language myself; I've worked on state machines and VMs for 6 years. AI helped a lot but the majority is hand written by me: the user-facing error messages, the whole website, and the large parts that are mostly boilerplate rather than hard were mostly done by Claude and then verified by me.

I'd love feedback on all fronts.

Playground: https://hxkhan.github.io/evie/play/

0 Upvotes

9 comments sorted by

3

u/Key_Detail15 2d ago edited 2d ago

What's a 'Go closure'? Is it data or does it contain native code?

Presumably there must be something that represents the code of a program which the interpreter executes. If it is not an AST and not bytecode then it must be something doing the same job.

And for a fair comparison with other non-JIT interpreters it needs to be data and not native code specific to a particular Evie program.

so the hot paths skip type dispatch.

There are 'hot paths' but no JIT?

2

u/hxkhano 1d ago

It's data. A Go closure is a pointer to a code body plus its captured variables. The code bodies are compiled into Evie once, and a script just picks bodies and fills in slot indexes, constants and child closures. So it plays the same role as bytecode, as a tree of (code, data) records, without a dispatch loop. The same binary runs any script, and it runs as WebAssembly in the playground.

"Hot paths" was loose wording on my part. The specialisation is picked once at compile time from operand shape (local or constant), and a cheap "are both numbers?" check remains. Nothing is profiled or recompiled, so there's no JIT.

1

u/Key_Detail15 1d ago

So it plays the same role as bytecode,

Well, 'bytecode' can be represented in different ways, so it is perhaps not wildly different.

For example, if there are N different bytecodes, then there might be N different handlers for those bytecodes, precompiled inside the interpreter.

Some data structure will represent the bytecode selections and ordering for any particular program. And a mechanism will exist to move on to the next bytecode-handler to be executed.

(Perhaps the nearest I've used for what you have was 'threaded code', where there was no explicit dispatch loop. But that used ASM and I prefer HLL code.)

In the past (like 20+ years) my interpreters used to run rings around everthing else, without my even trying. But now they're all catching up!

CPython is still easy to beat, but Lua, especially 5.5, is matching my stuff on some benchmarks, but it is variable (for some, Lua has the edge, on others mine is several times faster).

(However my language design is different: some features can make it easier to be fast, but then it has richer types which can slow it down. It is a bigger language.)

After looking at your results, I'm looking again to see if I can push mine a bit further.

1

u/hxkhano 1d ago

Cool man. Just a question, what host language is yours written in? And do you mind sharing the repo here?

1

u/Key_Detail15 1d ago edited 1d ago

It's in my private systems language. I no longer develop it or share stuff about it. But here is a document that lists some features:

https://github.com/bart-2026/langs/blob/main/MFeatures.md

If you look for the section on 'Label pointers and computed goto', it will mention special forms of looping switch that I now use for HLL dispatch loops.

Under an old account I once posted a survey of Fibonacci timings across multiple interpreters:

https://www.reddit.com/r/Compilers/comments/1jyl98f/fibonacci_survey/

This benchmark is just integer operations and simple function calls, but it is useful to get a rough idea of where an implementation sits relative to others.

1

u/Inconstant_Moo 1d ago

Compiling to closures is a general technique for replacing a VM. Here's the original paper by the bigbrains who thought of it.

https://www.iro.umontreal.ca/~feeley/papers/FeeleyLapalmeCL87.pdf

Here's someone doing it in Rust.

https://blog.cloudflare.com/building-fast-interpreters-in-rust/

I have seen a paper on doing it in Go which shows how and why it's faster than an equivalent bytecode VM but I can't find it rn, maybe OP has a link?

1

u/hxkhano 1d ago edited 1d ago

This bad boy right here https://planetscale.com/blog/faster-interpreters-in-go-catching-up-with-cpp

Edit: Nevermind it’s not this one.

1

u/Discordbothost 2d ago

The aggregate timing makes it hard to tell how much the specialized operators contribute. Could you run the same programs with specialization off and show the times per benchmark? That would make it easier to see which speedups come from dispatch and which are elsewhere in the runtime.

1

u/hxkhano 1d ago

I ran it. Times are in-process medians from 11 runs. "No fast paths" is Evie's -inline=false flag, which turns off everything the compiler specialises ahead of time. "No shapes" is a one-off build I made for this, with only the specialised operator closures turned off.

benchmarkfullno shapesno fast paths
classes23.7 ms1.03×1.30×
closures27.8 ms1.03×1.29×
fib338 ms1.48×2.00×
mandelbrot71.8 ms1.54×1.92×
matmul29.6 ms1.07×1.99×
objects28.3 ms0.95×1.24×
sieve53.7 ms1.03×1.90×
strings31.2 ms1.02×1.10×
geomean46.7 ms1.12×1.55×

So the operator shapes matter for arithmetic (about 1.5× on fib and mandelbrot) and not much else.