Rust for LLMs: Improved Performance and Safety

🗑️ Why use a garbage-collected language if LLMs are doing the coding? For decades, using languages like Java, Python or C#, was well worth the performance penalty. Sure, the same app written in C/C++ (or assembly...) would have been more performant, but would have also been riskier, harder, and more expensive to develop. But the cheese clearly moved. 🦀 Rust is now mature and well understood, and if LLMs are the ones writing the code and fighting the notoriously demanding compiler, then why not just write in Rust and take advantage of the improved performance and safety guarantees? It may not be the best fit for all apps, but for some projects Rust just became that much more attractive.

What performance penalty are you talking about? In typical backend applications, Java is nose-to-nose with C++/Rust. But Rust will never be even close regarding the ecosystem and dynamic properties of the language. It just was not designed for this purpose, unlike Java. Tools like Pragmatica Aether (https://github.com/pragmaticalabs/pragmatica) in Rust would be a nightmare to implement and use.Don't get me wrong, I love Rust; it's my go-to choice for all projects where Java does not fit. But the fact that LLM writes code does not change the niche where each language fits. The need to write code in a specific language is not and has never been a criterion.

Reading your marvellous post, I get more and more convinced the software architects have no idea about programming at all. Let me guess, you avoid writing code at all costs, because you really have gaps in your knowledge, right? It is much easier to draw arrows and rectangles under the mystical name UML, rather than write actual code? No offense, just observing obvious things.

Why not assembly? Writing code is the easy part. Living with it is hard.

Garbage-collected heap scales better than (explicit or implicit) malloc/free with the heap size, the heap fragmentation and the number of threads.

Alex Maltinsky Again, my claim was regarding the scalability only. CPU and memory overhead, pause behavior should be compared for given implementations and given workloads. And no, it is not correct that malloc always wins on CPU usage, memory overhead and pauses. Block headers and minimum allocation size are times larger for a typical malloc implementation. Average pause time of a modetn low-latency concurrent GC is below 1 ms on terabyte heaps and does not grow with the heap size.

Like
Reply

I love this angle! But let's not overlook the developer experience. Sure, Rust's performance and safety are enticing, yet many teams still prioritize rapid iteration and flexibility that garbage-collected languages offer. Sometimes speed to market outweighs the performance gains, especially in early-stage projects. It’s a balancing act.

I've worked in a variety of real-time systems in a variety of languages and have never , except for very rare times when hardware optimisaton was needed and only available in one language or the other, was the language ever the bottleneck. I've no doubt there are use-cases like high frequency trading or AV pipelines where it might make a functional difference to the business (again, hardware is usually the bottleneck). But the convenience of readability and maintainability of modern languages far outweighs the cons of performance drawbacks (which are rarely measured objectively).

I found out that LLMs struggle with languages that provide a larger abstraction surface, such as Rust / Haskell. For that reason, I'm currently doing my agentic coding in Golang, which I find absolutely horrifying to write by hand.

Why, when unprompted about what languages to use (or even whether to write code at all) do LLMs choose to write python scripting instead of Rust? When you have the answer to this, you will have the answer to why non-compiled languages should still be used.

LLMs didn't emerge in a vacuum. They were trained on what the industry actually wrote over the last 20-30 years. And that corpus is overwhelmingly dominated by Python, Java, JavaScript, C#, with C/C++ underneath as the systems layer. Python is massively overrepresented - not just in raw code, but in ML, data pipelines, tutorials, StackOverflow answers, research papers, glue scripts. Orders of magnitude more examples than Rust in the specific domains where LLMs shine (data processing, orchestration, ML, AI)

See more comments

To view or add a comment, sign in

Explore content categories