Does anyone think it would be possible to put the bun JS runtime (written in Zig) in a NIF via Zigler?

I have a crazy question - does anyone think it would be possible to put the bun JS runtime (written in Zig) in a NIF via Zigler.

If that’s possible could you run JS files without needing Node on the machine?


My motto is: you never know until you try it in production. So my advice is to put it in your company’s most critical application as a test.


I saw that Bun was experiencing Segmentation faults in some video.

So you will doom your Beam instance.

bun.js is AFAIK only available as standalone executable and not as a library, so I don’t think that’s possible. Best you can do is writing a port, as you can do with any executable



Did you end up going with the port method, and do you know how long it takes to do a call?

I’m currently using elixir-nodejs to execute javascript from elixir and it takes about 40ms for a single call, which I think is pretty bad. Was wondering if there’s a faster way.

Can’t edit my post but it takes around 8ms in production which is more doable for me. Still interested in knowing what you ended up doing :slight_smile:

Do you mean it was 40ms on your personal machine and 8ms in production? Are you still talking opening up ports to Node here? Thanks :slight_smile:

Yes 40ms in dev, but about 8ms in production which is ok. In dev I think it’s because the cache gets reset every time, on production there’s caching going on and it’s way better.

And indeed I was interested in the port to Node solution instead of using elixir-nodejs. Maybe it’s faster I’m not sure. But also if Bun worked with Zigler that would be amazing. Seems it should be possible

1 Like

Bun wraps WebKit, so you’d just use that instead. Anyways it was something I am thinking of (I used spidermonkey). GitHub - ityonemo/yavascript: Javascript embedded inside of elixir

Thanks @ityonemo, that looks like something I could use, I’ll take a look at the code to see how it works and maybe run it myself!

Just a warning it doesn’t work really except for the simplest cases and it’s also going to be incompatible with zigler 0.10.1 which is coming soon!

I’m also not completely sure spidermonkey is the best choice. I think tinyjs might be better

Ok thanks good to know. If I use it I’ll send over PR’s in case I fix those issues. Could be nice to just have that package working instead of me trying to write my own things based on your code. But maybe the latter will be easier for me, not sure yet, will see.

Before you get too deep into it: I’m also not kidding when I say that zigler 0.10 will be different =D

But especially, resources, which this depends on are going to look something like this. I’m still hashing out the API on this so even this is likely to change.