Bun is being ported from Zig to Rust

The reason I find this sort of comment annoying is that it implies that Rust actually reaches 100% safety, when it clearly doesn’t. Or alternatively implies that you can’t reach the same level of safety with Zig. Both those implications aren’t true.

The uninformend reader will read this as:

Yeah, with Zig you can get like 99% of the way to the safety that a Rust program will bring.

(only the second safe removed)

But the difference between those two sentences is still massive with Rust, so it seems disingenuous to hype up Rust saying the first thing while many naive readers will take it for the second thing.

So what is the difference?
Logic, Rust implementation, Rust soundness/type-system, Operating System and hardware bugs/exploits.

That second safe serves as a means to say that you have made sure that all those problems don’t actually result in any real problems that can be exploited, so when Rust is presented in a way where you easily can read it as if it took care of those problems, but you didn’t, that is where it becomes more like a advertisement trying to over sell their product, through cleverly technically correct language that still sells a false impression of what it actually is.

That it is sold that way makes me trust it less, they should just outright say we help you with many memory related safety issues, so that you can focus your critical thinking time on the remaining harder problems, instead of implying that general safety was solved.

I don’t like the way you framed it and I think that somebody who actually is interested in delivering that second safe (in safe program), also can implement a process using Zig that ensures the same or depending on what they do, potentially even better safety, than a Rust program (because that second safe is largely in the responsibility of the programmer, regardless of the language they use[1], but personally I would bet that if I used Zig to reach such a goal I would get there faster than if I tried to use Rust for it (partly because Rust would result in too much sword fighting time :wink: )))

The difference between Zig and Rust isn’t the potentially reachable safety, but how much responsibility you have to accept as the programmer to actually reach some specific level of safety, Zig requires that you accept more responsibility for what you produce, instead of trying to hide that responsibility by obscuring the problem and over selling ideas that aren’t actually delivered automatically/magically. Rust can help with some problems, it can even be the better tradeoff for certain problems/goals and certain workflows, but stop with the hype stuff and implying it had some absolute increase in the achievable quality.

I am willing to bet that a lot of the memory safety related savings in developer time are wasted by Rusts slow compile times, especially if the programmer using it has learned to not make so many memory related errors to begin with. Also if you have reason to care about those sort of errors you can still use a lot of other tooling in addition to Zig like code tracing, validation, etc., to close the gap between Zig and Rust in being able to handle memory safety and having an efficient workflow around that. Rust gives you one option that you can’t practically opt-out off (you get stuck with the negative effects of the tradeoff), Zig gives you many options that you have to opt in to, where opt in requires a higher time and effort investment (because you are bolting things onto Zig, or figuring out how to use them alongside Zig).


  1. except if the language is a completely proven chain from start to finish and its proofs are actually proving the right thing (the proof itself isn’t faulty) and then it runs on hardware in a way that faults get error corrected (and don’t result in mission failure like coming up with the correct answer, after the patient already died from the heart attack, in a too slow peacemaker) ↩︎

10 Likes

memory safety does not exist.

Indeed, this is the angle that we focused on in our recent video on the Anthropic-Bun and OpenAI-Astral acquisitions. I’ll put a link to the relevant timestamp:

3 Likes

I’m not a mod but please let’s avoid going over again the usual points of Zig vs Rust wrt memory safety. This discussion has already happened thousands of times and it never leads anywhere.

Discussing Rust here is not going to give you a balanced perspective on it, just like discussing Zig in a Rust community won’t give you a balanced perspective on it either.

So discuss Zig here and leave Rust discussion for other places that are better equipped to give you meaningful answers.

35 Likes

All i’m saying is that reliable software is hard, Rust helps make that process easier, and provides strong guarantees (that most software doesn’t need), but so does Zig, using assertions, orelse undefined, leveraging the type system, and comptime, unit tests, failing io, and failing allocators, fuzzing, and Smith fuzzing, you with all that you can get so far that for practical use cases it really doesn’t matter that you use Zig or Rust, in fact my guess is that Zig simpler spec, could potentially make it easier to certify and prove.

But obviously it’s also easier to hack things in Rust and not introduce issues.

1 Like

agree with you in general it doesn’t make sense to debate the Zig vs Rust, it’s always context/project specific, depends on the goals, the team, but in this case I find it relevant, since one of the stated reason of why they are trying Rust in the first place, is to leverage it’s builtin “safety” features, to eliminate bugs, crashes, and memory leaks that they’ve been complaining about.

4 Likes

To push back a little against this,I think I have a fairly nuanced and informed perspective on Zig and Rust, biased, if anything, in favor of Rust. And I am happy to engage in these discussions here, even if that amounts to seemingly repeating what was said before — there’s value in polishing arguments and observations, and of course there’s value in exposing new people to old arguments.

However. My personal precondition is that it needs to be a technically interesting and emotionally boring discussion. Spend N minutes clarifying your thoughts to yourself, than another M trying to find an unambiguous way to phrase your thoughts, staving off misunderstanding preemptively, and then add K minutes on top to cool down the wording, so that you engage the rational part of the brain of your interlocutor, and keep the stupid monkeys sleeping. :sports_medal: if you present this as a blog post with links to prior discussions!

But I am definitely not interested in debunking potshots in the latest social media scandal thread, filled with twitter screenshots and reaction videos (andrewrk is officially exempt from my “no scandals” rule :winking_face_with_tongue: ).

30 Likes

The problem I see is that you and other people who can talk about Rust in a balance manner are a minority and the probability that a discussion becomes heated is high, as the majority of the people who chime in do so by making partisan comments (one way or the other), especially now that we’re looking at a big controversial Zig project switching to Rust.

12 Likes

In my opinion the best “idea” of Zig is simplicity. It is simple yet powerful.

And with this comes quick understanding, readability, maintainability and many more…

The problem with these discussions, as well, is that slight differences in use-case bring about huge differences in how well a particular language/design may map to your exact problem. It is really hard to compare experiences when even two projects form a similar domain can easily run into totally disjunct sets of language-related headaches compared to one-another. This is doubly true in Rust where limitations of the type system can suddenly (and often unexpectedly) run you into a wall, while other people have no problem at all. There is really no headway to be made if you aren’t ready for a quite-involved discussion.

Discussing those particular cases often is interesting and educational, and even amongst those whom we’d agree are “experts” we find a lot of nuance and mixed experience. For example: you can contrast @matklad ‘s explanation of Tigerbeetle’s decision to use Zig, especially for allocation control, with his “Hard mode Rust” blog-post where he finds fine-grained control over memory suprisingly ergonomic! Nothing is so simple I’m afraid, despite what we like to think in a culture of yelling “skill issue!” at each other.

With regards to the partisan people - I think its safe to just ignore anyone who has too-fiery opinion on this or that language. If someones unable to recognize that software of enviable quality can and has been written in C, Zig, Rust, C++, etc. “despite” the language choice they made then you have a ways to go before I want to engage with you. Someone far, far smarter than me has chosen to use every language imaginable.

6 Likes

Oh nice, are you part of the boot.dev team? Always enjoyed the podcast, didn’t know this kind of content was being made too.

1 Like

It got merged:
https://github.com/oven-sh/bun/commit/23427dbc12fdcff30c23a96a3d6a66d62fdc091d

3 Likes

looks like io still C based

That was 0% Rust last week

But at the same time, no Zig code was removed because of that PR. I am not sure if there have been any feature additions, but else this is actually a (more than) 40% code (note that it’s not binary size) increase.
And the PR surpassed 1 million (!) LOC additions. I am not sure if it got reviewed by any human (it was opened “last week”, I don’t assume people can review that much code that short time; also the GitHub review panel doesn’t show any human approves).
This was the time for me to uninstall Bun (I don’t want to be the guy that writes this, but it’s just like that). I haven’t really used it for quite some time, so it’s “just” deleting some stuff. Also, this is going to be the time for me to use the Kiesel JS Engine more.

7 Likes

From the zig discord server:

“The CI marked the pull request as AI slop”

13 Likes

I feel the same. And I feel sorry everyone who actively using bun. If there is a chance that the rust rewrite going to be 1000% better than I would say the same I dont trust Vibe Coded code base in production 1m LoC merge is too much. Its AI written and I dont trust vibe ai in codebases that run AI application.

2 Likes

One interesting data point is that the original Zig code base was 640kloc (ai slop by Jarred-Sumner · Pull Request #30680 · oven-sh/bun · GitHub), and the Rust code base is 1000kloc (Rewrite Bun in Rust (#30412) · oven-sh/bun@23427db · GitHub).

Nearly doubling the code size wih a rewrite is insane, no matter the source and target language, no matter if manually done or automated. Time to put a wall around Silicon Valley and declare it an exclusion zone, obviously they’ve all gone mad there.

16 Likes

BTW Bun team forked zig compiler to be faster. Then they switching to rust?
It make no sense for me.

6 Likes

yeah that’s the part I still don’t understand, they obviously like the fast feedback loop, but now they are going to get the 3min recompile everything when you add a comma kind of loop, it really is bizarre

5 Likes