Hacker News new | ask | show | jobs
Show HN: Ant – A from-scratch JavaScript runtime in 9 MB (github.com)
8 points by theMackabu 39 days ago
Hey HN! I have been working on Ant for a while now, would love to share around now.

What is Ant? It's my JavaScript runtime, built from scratch over many hours of work. Much effort has gone into keeping the binary size small, around 9MB at the moment (6.5 MB with -Os). On my M4 Pro, the hono coldstart bench (examples/npm/hono/bench-coldstart.js) lands around 5ms, about 2.4x faster than bun, and 5.8x faster than node.

To keep things small, the engine ("Ant Silver") is hand-written, not a wrapper around V8/JSC/SpiderMonkey. The JIT is still a work in progress but it uses a fork of MIR as the backend.

Ant currently targets the WinterTC Minimum Common API, while also passing 100% the javascript-zoo compat-table tests, and is sitting around 64% on test262.

Why did I build Ant? Well, I wanted a runtime small enough to ship with CLI's and small Docker containers without having to drag along 50 to 100mb of just runtime. Ant in its current state is performant enough in some cases to compete with v8, but mostly in specific shapes.

Background on how it got here: https://themackabu.dev/blog/ant-part-two

Online demo shell/container: https://ant.ax

If anyone has questions about Ant, such as the engine, im happy to answer any of them! Feedback is also appreciated, if you run your own code and hit some edge case.

2 comments

This is cool, imagine this in a serverless environment

Previously with lambda we've had cold start issues, and cloudflare tried to address this with V8 isolates, but that doesn't have the full node env

Maybe this could make it so the code always runs quickly regardless of the env it's in... maybe

thats crazy but if u wanted to write js and it be fast and small size wouldnt it be better to write some compiler that compiles it into llvm?
llvm is big/slow to compile and doesnt really fit js dynamic execution well in most cases
u mean dynamic execution like when developing as in to reflect ur changes, or running on production hardware? for example if im in dev i def wanna be able ti tweak code in real time and have it instantly reflect changes for fast feedback loop but when in prod i want it packed tight and performant w/ all the flags on etc etc, so ideally i wanna be able to develop in dynamic but deploy to static. for exmaple in game im building rn, i have ts modules that swap in with optimized zig. there are strict api rules such that i can always tweak logic and optimize in ts and have the ai auto translate into native and there is a test that checks output memory to make sure its equivalent w/ bench test tool so it can just run in a loop until its done optimizing...this is beat pattern for me rn to treat ai as like some sort of second order compiler.