Rewriting in Rust
blog.jetbrains.com
blog.jetbrains.com
I really wished the documented their benchmarking methodology here, or at least cautioned the reader not to jump to conclusions based on the benchmarks shown.
GNU 'sort' performance can drastically be altered by the locale in use, the input, and the arguments given to the --buffer-size and --parallel options. GNU 'sort' is fairly conservative in how many threads it will use by default, and in my experience, much more so than uutils. This is because throwing more threads at 'sort' may make it faster (or may not), but also risks running out of memory. This is an issue with uutils, which is poor at deciding when to use external sorting:
$ export LC_ALL=C
$ for i in {a..z}; do yes $i | head -n $(numfmt --from=iec 512M) | tr -d '\n' >> input; done
$ time sort input > /dev/null
real 0m24.245s
user 0m0.896s
sys 0m19.161s
Here is the same command using the latest uutils commit compiled with 'make PROFILE=release': $ time uu-sort input > /dev/null
Killed uu-sort input > /dev/null
real 2m53.560s
user 1m40.634s
sys 0m59.847s
The process gets killed by the OOM killer. This is likely because uutils 'sort' decides to use 18 threads, instead of the 1 used by GNU 'sort'. I find it a bit frustrating that benchmarks are thrown out without any methodology or citations, because they are often trusted without question. These could be benchmarks from before uutils had localization, which was the case before 2025, and treated LC_ALL=en_US.UTF-8 as LC_ALL=C. In that case, of course it would be much faster than GNU coreutils, but it also means uutils would give you the wrong results for non-ASCII characters. There is, as shown above, much more considerations beyond speed that seemingly never get the time of day next to flashy benchmarks...Is there any effort from the GNU organization to solve long-standing issues and pain points such as locales?
As it stands I am generally averse to using GNU tools because my feeling is that they will be slow, clunky and exhibit arcane behavior in particular edge cases. ripgrep is significantly faster than GNU grep -R; fd than GNU find, etc.
For example, before LLMs were common, I once had to spend an entire day getting GNU flex and GNU bison to generate code that was: a) properly prefixed with a custom prefix, not yy_ et. al and b) did not use global variables.
I would have understood if, for backwards compatibility, this was gated behind a --sane flag or similar, but the GNU manuals were, at least at the time, under the confusing impression that what I was doing was advanced usage and used semi-fancy terms like "re-enterant" to describe what should be the normal behavior. I had to toggle several different knobs, some working for macros, others for functions, and the knobs were different for flex and bison.
POSIX locales in particular are an anti-feature, and I say this as a non-English native, so uutils adding support for them feels like bug-compatibility with GNU, not feature-compatibility.
Other issues involve the dynamic linking requirements of glibc and of the nsswitch in a world that would increasingly prefer to link things statically.
I am really saddened if the reaction is just that GNU is the old and stable is the main argument here. Because when you read many GNU documents and manpages, written years ago, you get the feeling that the original authors were looking to do things properly, make breaking changes where they were sane (hence POSIXLY_CORRECT), innovate (Emacs), and overall would not have been particularly swayed by the "old and stable" argument of traditional Unix distributions at the time.
The Rust community seems to be the one making exciting innovative stuff nowadays. uucore is more complimentary as well, ripgrep and fd are much more interesting. Sure, there may be certainly kinks, as you pointed out. But Rust programs can be debugged. Can GNU programs innovate?
Most GNU projects don't have a large overlap, if any overlap at all, between their active contributors. I suspect they behave far more independently than you expect. Also, GNU didn't invent locales, if that is what you are getting at.
> As it stands I am generally averse to using GNU tools because my feeling is that they will be slow, clunky and exhibit arcane behavior in particular edge cases. ripgrep is significantly faster than GNU grep -R; fd than GNU find, etc.
Those programs have their imperfections as well. Particularly, they don't account for arbitrary limits like PATH_MAX. See 'fd' stops before visiting the deepest directory without altering it's exit code:
$ mkdir -p $(yes a/ | head -n $((16 * 1024)) | tr -d '\n')
$ fd a | wc -l
3119
$ echo ${PIPESTATUS[@]}
0 0
On the other hand GNU find can visit arbitrarily deep directories: $ find a | wc -l
16384
ripgrep has similar issues: $ (while cd $(yes a/ | head -n 1024 | tr -d '\n'); do :; done > /dev/null 2>&1; echo a > a)
$ rg '^a$' a
rg: a/[...]/a: File name too long (os error 36)
GNU grep handles this fine: $ grep -r '^a$' a
a/[...]/a:a
> For example, before LLMs were common, I once had to spend an entire day getting GNU flex and GNU bison to generate code that was: a) properly prefixed with a custom prefix, not yy_ et. al and b) did not use global variables.Flex isn't a GNU project. I don't use or contribute to Bison, but I am pretty sure that is here:
https://www.gnu.org/software/bison/manual/bison.html#Multipl...
> I would have understood if, for backwards compatibility, this was gated behind a --sane flag or similar, but the GNU manuals were, at least at the time, under the confusing impression that what I was doing was advanced usage and used semi-fancy terms like "re-enterant" to describe what should be the normal behavior. I had to toggle several different knobs, some working for macros, others for functions, and the knobs were different for flex and bison.
Again, I don't contribute to Flex or Bison. I also do not use them. However, I will note that understanding the programs require some complex topics, specifically formal languages and automata. I am not entirely surprised that some of the documentation can be a bit difficult to understand.
> POSIX locales in particular are an anti-feature, and I say this as a non-English native, so uutils adding support for them feels like bug-compatibility with GNU, not feature-compatibility.
They are also widely supported by other implementations. It would be harmful to everyone if we were to disregard them. Also, as I mentioned previously, they were not invented by GNU.
> Other issues involve the dynamic linking requirements of glibc and of the nsswitch in a world that would increasingly prefer to link things statically.
I am a committer to glibc, but this isn't really my area of focus. You are free to discuss it on libc-help@sourceware.org if you'd like.
> I am really saddened if the reaction is just that GNU is the old and stable is the main argument here. Because when you read many GNU documents and manpages, written years ago, you get the feeling that the original authors were looking to do things properly, make breaking changes where they were sane (hence POSIXLY_CORRECT), innovate (Emacs), and overall would not have been particularly swayed by the "old and stable" argument of traditional Unix distributions at the time.
We make breaking changes. I recently changed 'printenv' and 'env' to safely quote their output. I will note though that although you want us to make more changes like this, others get quite angry at us when we do. Even changes that aren't breaking cause angry mailing list messages. We can't make everyone happy.
> Can GNU programs innovate?
Individual GNU projects are free to innovate as much or as little as they want.
Unfortunately, I find this confirms all my fears.
Whether or not ripgrep, fd, sd, et al. have some bugs left in them or not, the fact remains, when they do work (which is 99%+ of the time for most users), they are significantly more pleasant to work with. More pleasant = more use = more eyes = the bugs get fixed in the long run (as GNU should know from it's history!).
I wish everyone all the best, but I really do see a lot of these tools going the way of X.org in the next 10 years. Or, more likely, the way of csh.
> However, I will note that understanding the programs require some complex topics, specifically formal languages and automata. I am not entirely surprised that some of the documentation can be a bit difficult to understand.
And it has every right to be, when it is discussing these topics. But not polluting the global namespace and not using global variables is not an advanced request!
(if you wanted to be snarky, you could say that Fleet dissolved into thin Air)
The reason for this is pretty straightforward: Incrementally porting a codebase from another language to Rust (especially if it's not C) is a deeply unpleasant experience, because the interop tooling isn't good enough and you spend most of your time fighting it. Consider the case of rewriting from C++; in the simplest case, you use bindgen and cbindgen, which only work with extern "C" functions in both languages. So you effectively have to rewrite each API first from idiomatic C++ to C-in-C++, then translate to C-in-Rust, then rewrite again in idiomatic Rust. And then repeat for the next API. And so on. It's not going to take long for most programmers to go "screw it, I don't care what Joel said, at least when I rewrite all my work I'll be doing it in one language where anything can call anything else". cxx and autocxx modestly improve things, but still leave you with an impoverished API vocabulary and similar problems, and you still have to do the three-step rewrite for each API, one at a time.
This is also why TypeScript, Kotlin, and Swift worked so hard to have seamless two-way interop with JavaScript, Java, and Objective-C. Without that, they couldn't have credibly promised to replace the earlier languages (because large existing codebases where a rewrite wasn't economical would still be stuck with them), and so couldn't have gotten off the ground.
Crubit is supposed to fix this for C++-to-Rust, and I'm rooting really hard for it, but it's not there yet. For most other languages, a Crubit-like thing probably isn't even possible in principle, because the differences are too great.
(I'm not talking here about the use case where you started with a garbage-collected language but have hit a performance ceiling with it, so you rewrite just the most performance-sensitive parts in Rust, while continuing to develop the rest of the codebase in the original language. This is often a great way to use Rust, but it's solving an easier problem and so poses fewer difficult tradeoffs.)
Well yeah, that has obvious practical reasons: unless you're using C/C++, you can't really link Rust code with your codebase (or you could theoretically do it, but in a way that would affect performance and/or complicate your architecture). So, if you're going to do it at all, a full rewrite makes more sense.
Was just testing latest gen LLM capabilities, and decided to give it goal of rewriting a small opensource project in Rust. (Should be noted: was not some tiny library, but an actually useful network service).
It completed the entire rewrite from typescript to rust in about 2 hours, ~600k tokens used. Worked perfectly on first try with no follow up changes required. Memory and CPU usage now a tiny fraction of TS version (obviously). Rust code was simple, easy to read, accurate test suite, etc.
I was pleasantly surprised.
Obviously bigger code bases with more complex business logic will likely struggle here, but there are some advantages to "RIIR" when performance matters, even security benefits aside. Rust can help squeeze more juice out of old hardware; reduced memory footprint especially helpful with current RAM prices.
For small services where operational cost matters, having LLMs "rewrite it in rust" might be worth the spend.
I suppose if it is like the Zig Rewrite where essentially all development is being done by Claude, I can imagine this making sense.
But in any other case, you had a codebase that presumably you wrote, you could reason about, you could refactor etc. and then you made it into a completely unintelligible code base, which even if written cleanly will take a long time to reason about. Typescript to Rust is not just syntax changes. It doesn’t make sense to me, unless you believe you will be completely out of the loop in managing this code in the future.
Not something I need to maintain much going forward, so I have no reason to manage the code manually ever.
Amidst this, just let me try to give my own experience with language while working in a field where it doesn't have much traction (scientific/numerical programming). A couple of years ago, after being tired trying to make Python faster, I was looking for a language to write simulation code in. Fortran (and C/C++) has been the go-to choice in my field for decades but I wanted to try a modern language. I tried Julia but the workflow didn't come naturally to me. Also by default, it also wasn't ahead-of-time compilable. Rust was my second choice but it's type system/design, expressiveness and tooling (rust-analyzer) won me over. I have written so much of it and I really enjoy writing it. Borrow checker isn't really an issue 99% of time when writing scientific code. And when it is (self-referential data structures), you can just use an arena (or something equivalent). The C/Fortran inter-op is great so it's still so easy for me to build my own abstractions on top for the more general stuff like solving ODEs and sparse matrices.
And of course, there is speed, memory safety and ability to parallelize things so effortlessly (rayon is magical), but I feel those were never the things that actually won me over. The language was just a joy to write.
My company gave me a brand new, beefy Macbook pro and that thing can barely handle IntelliJ sometimes...
I feel like a lot of the love for IntelliJ is a sort of Stockholm Syndrome combined with relief at not using Eclipse.
(Imho, having cargo available is often already worth a RIIR.)
(Note also that Bun inherently needs to use a lot of unsafe because a large fraction of its internal API surface is interlinked deeply and pervasively with that of JavaScriptCore.)
https://en.wikipedia.org/wiki/Garbage_collection_(computer_s...
https://users.rust-lang.org/t/reference-counting-garbage-col...
Swift has refcounting built into the language and assumed everywhere. You could always use raw refs in Swift, but that's not the norm.
E.g. in Swift the reference counting is automatic a d implicit
In C++ it is manual and explicit
I understand that their compiler in Rust is better. And any other language could compile it using the same SIMD instructions.
Oh no, what are we hiding?
> introduces bugs you already fixed.
Isn't this why every bug fix gets a unit test?
I appreciate rewrite isn't always the answer but it's a strange post when the authors should be giving constructive ways forward so we move to Rust and then use their 1k star Django clone they link to.
Instead anytime a question is posed it falls back to "sometimes" and little detail after that.
Citing a nine year old paper instead of something newer or doing their own benchmarking wasn't ideal either.
Honest question, at what point is the Stack Overflow Developer Survey not representative of the average software engineer, many (most?) of who no longer use Stack Overflow?
I'm afraid the author completely missed the point here. Typst is not more readable than (La)TeX because it's written in Rust, but because its DSL was so designed. It could have been implemented in PHP that the result would be exactly the same.
Same thing with the auto-unroll/SIMD arguments. AFAIK, it's LLVM that's doing the job, there is nothing theoretically preventing a {language} compiler to obtain the same results.
Where Rust shines w.r.t. other similar languages though is that its strict memory model lets developers push further memory/concurrency optimization without sacrificing safety – which she highlights in the GNU/coreutils sort comparison.
Is this really an alternative? I would never replace battle proved TeX with consistent syntax, build for processing text, with great fonts, thousands of plugins for some Markdown mess, which is, in addition, paid.
Only because it is written in Rust, not in C.
I'd argue the syntax is much simpler, more modern, and perhaps even more consistent (the fact that in TeX you can change the meaning of the escape symbol or the comment symbol is pure insanity IMHO). It can use any font, and the feature you know from LaTeX, a compiler, is free. Only the web application has some premium features. It's more like Overleaf. It's also several orders of magnitudes faster and has actually helpful error messages.
The fact that it was written in Rust is less than secondary.
Also, TeX was written in WEB, not C.