logoalt Hacker News

Rewriting Bun in Rust

403 pointsby afturneryesterday at 9:49 PM207 commentsview on HN

Comments

didibustoday at 12:01 AM

Article did a decent job of showing discipline and care and human involvement to assert the automated rewrite was done diligently, as best as it can be when using AI for it. I does make me feel a bit more comfortable about it.

As an aside, I don't know why anyone would not want to use a memory-safe (and possibly race-safe) language in 2026. Rust gives you that in a performant package, so if you are turned off by GCs and immutability for performance reasons, you still have the option to use Rust.

I can understand when you need the absolute best performance and you decide to drop to down to C++, and I also relate with just personal preference, but beyond those it seems a no brainer to me.

show 7 replies
Philpaxyesterday at 10:30 PM

Without commenting on Bun itself as a project, or the nature of the rewrite, it can't be good for Zig that a naive rewrite away from it fixed memory leaks, improved stability, shrunk binary size by 20%, and improved performance by 5%.

show 11 replies
sashank_1509today at 12:41 AM

I think the important thing is this is much cheaper than hiring a software engineering team. They could have hired me for 200k and I could not do this in a year. I do not have the context, and I do not know Zig or Rust, perhaps I could pick it up in a month, but I would be extremely slow.

Forgetting all the predictions about singularity etc, at the very least AI as it is now, is going to make it very hard to justify hiring a SWE for 200k. I will say, at the very top for a software heavy company like Google or Anthropic, they will still hire excellent engineers to create new software that AI is not very good at.

But for companies where software is simply a cost center. Like Walmart, or Target, companies that were already outsourcing software development, or using cheap H1bs, now they have the alternative of AI which is much better than even hiring an average software engineer for 200k. This is a sea change in the job market, it’s going to have a pretty big effect as it is right now. US has around 1.6 Million software developers, this number is going to get cut drastically, the very top, say an L6 quality in FAANG will be fine, the average in a no name Bank, or the guy building the website for McDonalds is out, he needs to learn something else or he’ll end up without a job soon.

I would not have predicted this a year ago, now it seems clear that this will happen. Just shows how much of a sea change we have witnessed just like that.

show 6 replies
pier25today at 12:58 AM

Personally I don't care that they used AI to rewrite Bun to Rust. Even if 1.4 is not good enough it will probably get better over time.

What has pushed me back to Node is seeing how amateurish the transition has been handled.

- No LTS support for the Zig version regarding CVEs etc.

- Huge bugs like the 3MB memory leak mentioned in the blog post abandoned in the Zig version to basically force people into the Rust version to fix their apps in production.

- Zero involvement with the Bun community about such a major decision. One day it was "stop the drama I'm just playing with this" and a couple of days later "yolo merged to main".

Jarred basically keeps operating as if he was a lone hacker working on his personal project.

show 3 replies
dabinattoday at 12:13 AM

> This Rust rewrite would've taken a team of engineers with full-context on the codebase a year of work. With 1 engineer using Fable & closely monitoring Claude Code, we went from start to 100% of the test suite passing on all platforms in 11 days.

This is impressive from a technological standpoint, but it does gloss over the fact that it would have cost $165k in tokens were Bun not part of Anthropic.

The comparison here isn’t completely fair - it would take a small team a year to port it if they spent $0 extra on it.

I’d be interested to see a comparison between spending $165k in 11 days on Claude vs splitting that between 50 people over 11 days for a line-by-line rewrite of the Zig code. I suspect Claude might be faster and therefore cheaper, but maybe not by a lot.

show 6 replies
theLiminatoryesterday at 11:21 PM

That's the power of a strong test suite. LLMs excel when you have verifiable rewards. I imagine we'll get a lot more rewritten in rust projects in the future. Rust is also an ideal target for such rewrites as it offers a lot of verification (via its type system) and is low overhead with zero-gc. There's less and less reason to use GC'd languages in the agentic coding era.

I think Rust is a locally optimal target for LLM coding, we might see a better language in the future, but I think Rust will dominate for quite some time.

show 1 reply
losvedirtoday at 1:27 AM

In what ways does Anthropic use Bun? I know it's used as the "runtime" for Claude Code, but rather than porting a million lines of Zig to Rust, why not just port Claude Code to rust and not need to bundle a JS runtime at all? Does Anthropic use Bun otherwise? Maybe for JS execution tool calls in Claude responses?

show 1 reply
YuechenLiyesterday at 11:23 PM

>Combined with the Rust rewrite, ICU changes, and identical code folding, Bun's binary size shrinks by ~20% on Linux & Windows.

People who are surprised by this probably has not seen what Zig code actually looks like. Zig's explicitness and lack of abstraction have a real cost that it is basically one of the most verbose programming languages I've ever seen, it's somehow even more verbose than Go. Basic features of modern languages like pattern matching and generics, and as you can see, having to manually clean up everything means that if you forget once, it's a memory leak. Having SOME abstraction is actually good if it prevents you from making mistakes.

Ironically, Zig is a programming language that's probably best written by LLMs, since they can actually tolerate the verbosity.

show 6 replies
nzoschketoday at 12:10 AM

> Historically, rewrites are a terrible idea.

This changed for me over the last 5 years.

The first scenario was joining a company where a software product barely worked. We did the traditional incremental refactoring / rewriting, but eventually learned how rotten the core was that rewriting from first principles was the best path forward.

The lesson learned here is that the conventional wisdom probably only applies to rewriting complex but working systems.

Then multiple scenarios in the agentic coding age. Between day jobs and hobbies I've reproduced major chunks of complicated software like Salesforce, Gmail, Pioneer Rekordbox with very lean teams.

Much like the blog post, the trick is to get an excellent verification loop with a compiler, linter, and test harness / test suite around the core behaviors.

It's feeling more and more that designing and implementing comprehensive test harnesses is the real work, once you have that let the LLM cook.

show 1 reply
hansvmyesterday at 11:35 PM

Every time I've rewritten a major project I've made it smaller and faster while fixing all the major bugs and most of the minor ones. My current team has had similar experiences. I'd be curious to see what a Zig -> Zig rewrite of the same magnitude would have done for quality.

thevinteryesterday at 10:04 PM

One thing that I found interesting is that most of the discourse surrounding the topic happened with the assumption that the rewrite was happening with an Opus-like model, and not with Fable. Those assumptions, at least partially, were used as arguments against the fact that the rewrite was feasible and/or a good idea.

Clearly the model itself doesn't completely change the narrative, but at least as a note to myself, I would like to be more careful with assuming the capabilities of the models used internally by Anthropic and affiliated orgs.

show 1 reply
bel8yesterday at 10:56 PM

> Claude Code v2.1.181 (released June 17th) and later use the Rust port of Bun.

It seems the reports of Bun's death have been greatly exaggerated.

Buttons840yesterday at 11:59 PM

I've always felt [0] the people who created Bun had, as their first and foremost goal, a desire to use Zig--and that's great, I like Zig, I like when people build things their own way.

However, I've been skeptical of using Bun, because I want a project whose first and foremost goal is to build good tools that achieve the objectives of the project.

It reminds me of asking game developers: Do you want to build a game, or do you want to build a game engine? Building a game engine is fine, but if you're goal is to make a game, then building an engine is a poor way of achieving your goals.

Likewise, I've wondered if the creators of Bun wanted to build better JavaScript tools, or if they wanted to use Zig.

[0]: https://news.ycombinator.com/item?id=35970044

show 1 reply
achristmascarltoday at 12:14 AM

I was fairly skeptical about the rewrite when news about it first started going around, and I still don't plan on switching anything to use the Bun rewrite anytime soon, but I appreciate how detailed and well-written the blog post is; it also seems to be primarily human-authored, in my opinion, which is refreshing.

The most significant revelation for me was that Claude Code has been using the rewrite without much fanfare since June 17th.

smasher164today at 3:22 AM

It's still shocking to me that the approach taken wasn't to have Claude write a tool that translates Zig to Rust. I imagine it would've been cheaper, deterministic, and each iteration would produce a better tool.

show 1 reply
ianm218yesterday at 11:30 PM

Inspired by this project I ported most of Valkey to Rust here valdr.dev .

The coolest outcome was being able to run a redis comparible store on an a cloudflare durable object so you do I.e. rate limiting for free with little infra.

subytoday at 12:58 AM

I'm so jaded at this point. The AI translation from Bun to Rust doesn't bother me, I think it's interesting, but that this blog was so clearly written by LLM's is offputting for some reason. I think after having to interact with LLM's for much of the day, it's exhausting to read LLM speak in so many things I see online. It feels almost disrespectful to the reader. It's written from a first person perspective, but Jarred did not write these words.

I was looking forward to this blog post too, but in retrospect I don't know why. I could have had an LLM generate a hypothetical of what this blog post might have looked like and it would have probably been able to get close.

I feel like we've replaced unique voices on the internet with the same style / author, which might be more tolerable if the breathless LLM writing style wasn't so jarring. Contrary to the amount of times "But honestly" or "genuinely" is mentioned, nothing about having your LLM speak for you feels honest or genuine.

I know it's not cool to leave responses like this, but I'm really tired of all of this at this point. The ironic thing too is that it might actually be better to have LLM written text be so distinct so that you can still pick out when a human has actually authored something. Again, this is a blog post from Anthropic about having an AI translate 500k+ lines of code in 11 days, so I guess my disappointment is my fault for expecting otherwise.

show 2 replies
anonyonoortoday at 1:00 AM

I think we're finally getting to see a glimpse of the future. People and LLMs, working together. (And doing it really well.)

It's pretty exciting.

duhhhhh1212yesterday at 11:12 PM

Where is the cost breakdown? I feel like this would be the easiest number to determine and write in this post. It's hard to believe that there have been no problems/downsides since the port.

show 1 reply
quux0rtoday at 2:09 AM

Something that seems to have flown under the radar is that bun was originally a rewrite of Evan Wallace’s work (for those that don’t know, he’s a co founder of figma). What I’d love to know is if Evan’s implementation is largely independent and, if so, says a lot about his skill (even more so than the rest of his impressive catalog) to have a reference-able implementation for what it turned into. Super cool to learn the original implementation motivation for Jarred though.

minimaxiryesterday at 9:55 PM

Adding bespoke animations via Claude Code to the blog post is definitely thematic. It's unclear if they're useful data visualizations as they take a bit of time to parse, but they're neat.

riftytoday at 1:49 AM

Super interesting!

I feel like people will make the wrong comparison with the cost to complete. $165000 should be compared to not the cost of a programmer going line by line by hand but someone designing a transpiler from zig to rust. The time to complete is impressive though, if you could spend $165000 and a year of time to find out the rewrite project worked, or instead spend that in a month, you'd probably take that month now that this proof of concept exists out there.

WhyNotHugotoday at 2:18 AM

> around $165,000 at API pricing

This is the bit I was really curious about. Definitely not something within reach for us mortals.

didibusyesterday at 11:56 PM

> to exhaustively come up with reasons why the changes create bugs or do not work

My biggest issue currently, is I can't seem to get a code review that's about the simplicity of the code, and no /simplify ain't it. Removing certain bugs and generally working seems to be doing alright, especially if it's following either an example code (like in the Bun rewrite case) or a well defined "spec" of how to proceed.

pier25yesterday at 11:53 PM

> Compiler errors are a better feedback loop than a style guide

So essentially this whole re-write was about making Bun LLM compatible.

surroundtoday at 1:10 AM

It seems that Deno made the right decision by choosing Rust from the get-go.

frollogastontoday at 12:13 AM

"I used a pre-release version of Claude Fable 5 for much of the Rust rewrite."

It'd be interesting if Anthropic became a general software company just because they have access to models that aren't yet released, possibly export-banned.

incognito124today at 12:05 AM

> In Bun v1.3.14, every build leaks about 3 MB, forever

I'm sorry but that is insane, how was this never fixed before the rewrite?

show 1 reply
tangenteryesterday at 11:39 PM

Should we brace for another front page Zig donation announcement? A fast follow with a “Why Zig?” penance piece, replete with anecdotes about how it is the only true way to express oneself?

SergeAxyesterday at 11:39 PM

I still think that generating a Zig-Rust transpiler would be a better approach, given all the LLM quirks, including the ability to just /goal the model with binary-identical LLVM bytecode.

However, an open-sourced tool like that would've greatly harmed the Zig ecosystem and community.

show 2 replies
ares623today at 1:46 AM

What does it say that it took 2 months to write the blog post? (or at least have it published)

show 1 reply
Barrin92today at 12:44 AM

the thing I don't understand about this, given that the goal was a line-by-line transpilation, and the author had already transpiled it once from Go to Zig, why not write an actual transpiler? A problem is as complex as the smallest program required to solve it, and having an LLM, which doesn't produce deterministic output churn through almost 200 grand when you only need to write a deterministic program maybe 5% of that size seems like not a great way to go about this

giancarlostoroyesterday at 11:30 PM

So I kept hearing that the author did this purely because Anthropic wanted a PR story, but reading this entire very well written post, with meticulous detail, what say you now? I never thought it made any sense for him to do this just because Anthropic asked him to. Sometimes you find yourself fighting the stack you're currently using, and another stack (or programming language) looks like it would alleviate a lot. LLM was just another tool in his toolbelt. I had already ported projects that were old and abandoned before using Claude Code, so I knew it was possible.

show 2 replies
DobarDabartoday at 12:20 AM

[dead]

fernando-ramyesterday at 10:49 PM

[flagged]

show 1 reply
rvzyesterday at 10:30 PM

As expected [0] [1], this was a clear advertisement / marketing opportunity of Anthropic's Fable model on rewriting Bun (which powers Claude Code) from Zig into Rust.

Something that would have taken hundreds of developers now took 1 developer with Fable.

Now Claude, rewrite Claude Code from TypeScript to Rust. Make absolutely zero mistakes.

[0] https://news.ycombinator.com/item?id=48073893

[1] https://news.ycombinator.com/item?id=48240829

show 2 replies
classicposteryesterday at 11:12 PM

This slop rewrite introduced new vulnerabilities and regressions.

show 1 reply
dfabulichyesterday at 11:21 PM

This blog post further undermines my trust in Jarred.

He makes it sound like Claude did a fantastic Rust rewrite, and "the work continues."

But when the Rust port merged to main, the state of the code was very, very bad. There were 13,000 instances of `unsafe`, no Miri tests at all, and, sure enough, it exposed UB in safe Rust. https://github.com/oven-sh/bun/issues/30719

Observers could see this coming from a mile away, objected strongly to using AI to RIIR before the code merged. Rather than incorporate feedback and get the code ready for production, Jarred gaslit us all, right here on HN. https://news.ycombinator.com/item?id=48019226

Just 9 days before he merged the Rust rewrite to the main branch, Jarred wrote:

> This whole thread is an overreaction. 302 comments about code that does not work. We haven’t committed to rewriting. There’s a very high chance all this code gets thrown out completely.

It's plausible that Bun's Rust rewrite is now in much better shape than it was in May. But a blog post like this would have been a place to apologize, to accept that it was a very bumpy rollout, to acknowledge that public messaging was extremely poor, and to earn back our trust.

As it stands, I guess I'll have to run my own tests to try to evaluate whether Bun 1.4 is ready for prime time, because I just can't trust Jarred to give us a straight answer.

show 3 replies
himata4113yesterday at 11:58 PM

They didn't mention the cost of this. Assuming mythos was somewhat involved I'd extrapolate this as: 128 x20 max accounts needed which comes at $25.6k or over 75k in api costs. For 75k you can hire a team of engineers that would produce a better result with sematic conversion and other tricks used in porting from language A to language B at the cost of maybe taking 1 month instead of 10 days.

I will be a lot more excited when this is possible with <10k of api costs.

show 3 replies