I recently discovered that one can apparently distribute Rust projects on npm by compiling to wasm. action-validator used to do this. Had been thinking about something like this.
Imagine being able to use only 1% of the machines you used to require, by migrating away from Python. This is very realistic for companies doing heavy computational work.
I'm not denying that domains exist where being I/O bound is a thing. For those cases Python can be a fine choice.
For cpu bound stuff the language makes potentially an enormous difference; but then you get to trade off: eg. if you're not gonna need a fast language you are free to choose based on other considerations.
Might still both pick the same language though ;)
I'd make the case that everything on a computer is CPU bound depending on scale, even your crud app. Half the time when somebody is saying that X is I/O bound, they actually mean that it's bound by the performance of their database - which wisely, in the real world, is not written in python.
edit: and, of course, things in python that would run terribly slow if written in python become primitives, which are written in C. Python is a C program.
As with anything performance related you need to profile the code with realistic data/workflows and identify the parts that are slow.
Typically, doing things like changing algorithms, data structures, careful use of caching, reusing calculations, etc. are more important to performance than the choice of language.
The choice of language determines the extent to which those things are possible. In case of Python using C libraries sometimes means that you pull data from somewhere, hold them in Python memory in very inefficient way, pay for transformation to another form that C library uses and then do the same in reverse at the end. Perhaps even more times if C doesn't handle everything. "Use C libraries" often works, but is not universal solution.
For example, PyTorch (and numpy IIUC) store matrices/tensors as a 1D array of numbers. This is more memory efficient as all the data is colocated.
They use a technique to store the distance within the array to move when moving along each axis (strides). This allows for operations such as transpose to be swapping the array and stride values instead of performing an expensive array/vector copy.
Another example: using string formatter or join instead of separate concatenations allows the compiler/language to compute the size of the resulting string up front (if the language/library supports that) rather than allocating on demand.
Another example: using a hash map/set instead of an array to check for the presence of strings.
(For big data you can use Python to drive some native code frameworks - it is good at that, for tiny data it’s irrelevant because there’s not much to do, but the moderate case gets awkward).
In mid-2013, NewsBlur described in some detail their deployment and statistics. Python/Django, 48 servers. I confidently calculated that, with implementation efficient, one would be sufficient, though with little headroom, and further vertical scaling might have started running into I/O limitations. (I doubt a single server would be possible any more.)
It’s popular to scale horizontally far earlier than you actually need to. And if you can commit to sticking with vertical scaling (single big machine), you can simplify (and further speed up) things enormously.
I don’t know about now, but five years ago HN ran on a single server <https://news.ycombinator.com/item?id=28479595>, though with a standby machine also present since 2017ish.
Personally I think it’s a very good trade-off for vastly more businesses and services than actually practice it.
I suspect I may have seen more systems run into availability problems from unnecessarily distributed architectures than from hardware failure, and I’ve definitely seen costlier development due to it.
In all fairness 6,000,000 messages per second across a single socket is likely an unrealistic scenario but application stability over multiple months pushing out message traffic across many sockets from many servers under a single application process is a realistic concern as is number of simultaneous open sockets.
The only JS-native answer is to use typed arrays, which is using a sledgehammer to crack a nut.
I've seen this at almost every company I've worked at.
Thing is, the TS app weighted around 4GB overall and took 2s to do its thing. [A backend process, an http api and a static website generator].
I needed to decrease the size and increase performance dramatically,to be able to put it in a 2GB 2vcpu instance, which costs $12 monthly. Otherwise it would eat the profit.
Claude ported it to Rust, in around 2 days total. And it went down to 1.5Gb max, and 1/10 of the CPU usage. Now it sits in the aws europe zone making money.
Apparently a lot of the node baggage was due to Garbage Collection, which Rust doesn't need. Also, immediately transforming incoming JSON to binary data helped.
Yes, to both: claude wrote the initial architecture, under my guidance. As I mentioned it was a PoC, so the first pass was "quick and dirty". Shit the original web server was React [which i didn't count for the comparison because barebones node can serve static pages as well.
It has been a cool experiment which started as a crazy idea, but now as I said gives me some spare change. I just SSH tunnel every day or two and load the web page to see how things are going.
And python being interpreted and dogslow means any heavy computation you write in pure python needs to be offloaded too instead of just putting it on a threadpool, again making your architecture more complicated.
Add in serverless functions, which need startup, and now something that should have taken microseconds will take seconds.
Node is JITed at least, but still no shared-memory multithreading, so it still encourages all the architectural bloat.
Depends what you are doing. Not a problem for something like a CRUD web app. Not a problem for most desktop apps.
> heavy computation you write in pure python
Why would you write heavy computation in pure Python?
It didn't start that way, but people kept adding new features and finding new use-cases.
That's what I'm dealing with, anyway. It is, in some ways, a good problem to have: people use it, like it, engage with it.
100x performance gain on on-prem hosting means everything to hardware costs.
The biggest differentiator is proper thread support. You can handle things concurrently within a single process and not start one or more processes per concurrent user. Go can do this, too.
The secondary is just having a chance to rethink the architecture. Do something smart.
The third is language and ecosystem features that encourage more correct software. Rust beats Go here. Too many specifics, nothing new. Haskell can do this, too.
While Rust is awesome, a lot of times the only apparent reason to chose Rust over C is virtue signaling.
Update: like I said, Rust is awesome and has so many advantages over C it's not worth a discussion really. But again I see that many projects are choosing Rust not because of merits but simply because it's a fashion.
Rust checked arithmetic is built into Rust's standard library (std) via explicit methods on primitive integer types (such as checked_add, checked_sub, checked_mul, and checked_div), which return Option<T> and evaluate to None on overflow. There's a known tradeoff of some speed, which is fine for my purposes because I need reliability more than raw speed.
I'm longtime C coder so I know how to do this in C. Rust strong types and static analysis make it so much easier to do correctly.
That seems like an extremely dubious claim.
Rust is just a lot more pleasant to work with in every possible way. C has the abstractive capabilities of a deaf-blind toddler.
Even very basic abstractions possible in basically every language, like say a type that holds JSON text, is not possible in C.
Update: In fact, you can also build quite reliable abstractions around incomplete structure types. Those abstractions are better than what C++ adds, where the abstractions in the header are all very fragile.
For example: suppose you need a container to hold ints. But it also needs to be able to hold other types. In C++ this is trivial, as in virtually all modern languages. In C this is impossible.
You can have a generic memory backed storage + accessors. But if you rely on void pointer functions, you have to remember every time to cast and pinky promise to only store one type. It’s very, very easy to make a mistake, and you will.
Most abstractions that we take for granted in modern languages are straight up not possible in C, or at least they are extremely incomplete. Part of that is because you can’t get C to do anything automatically. Every function call must be manual.
Here is an example for a generic vector type: https://godbolt.org/z/7MdGqcdbq
Your mistake is believing that you need native syntax for such feature to be possible. But this is not true.
And yes I'm aware of intrusive objects using macros, I've done this myself before. And you can even do evil stuff, if you want, like make `[]` work with them. But it's not reliable and it most definitely is a hack. Macros are like templates but if you strip out all of the type awareness.
We could probably go back and forth all day, so I'll just leave it here. I don't think you can reliably make abstractions in C, even pretty primitive ones, due to it's weakly typed nature combined with a primitive type system. Other languages don't have both. Go has historically had a primitive type system, but it was at least fairly strongly typed. Most modern languages are both strongly typed and have an in-depth type system.
It's not that these things are 100% impossible in C. It's that the language will fight you, will make it as difficult as possible, and the compiler will not check anything. In C, it's pinky promises all the way down. That works on a small scale but falls apart very quickly IMO. It's not about syntax or niceties, it's about the type system and what it does, and does not, guarantee. C guarantees basically nothing so you can't trust anything, ever.
This isn't just annoying and bug prone, it's also not very performant. If you've ever programmed in PHP then you know the annoyance of constantly having to verify everything. It's expensive. That's why std::sort is fast, and C's qsort is dog slow. The lack of a real type system makes many simple problems very difficult to solve in a performant way.
Those types can be written in a way that C's type system checks type safety, and my example was of this kind. No "pinky promises" necessary. In fact, these types are very similar to templates in C++. I would even agree that there are bad, but just in the same way templates in C++ are also bad.
And finally: you can also write a sort that inlines its comparator in C as well.
That’s not to say C++ is perfect, it’s clearly not. It’s just that C is worse. The way I see it, there’s really no reason to ever write application code in C. It will take more code, it will be more buggy, and it will most likely be much slower. The reality is that garbage collected languages do often end up being faster because most allocation techniques in C and C++ are naive and expensive.
Which is why we see almost zero applications written in C. They’re written in Java, dotnet, Go, and others. Only low-level libraries are written in C these days because writing C sucks ass.
For example, you cannot even write type-safe generic data structures in C. You just have to muck around with void pointers. You might reach for macros to make it "nicer" to use, or write "type-safe" functions that cast for you, but that's mostly a veneer.
If you'd said another memory safe language I might have been on board, but C? We've seen a complete collapse in the ability of software to go un-hacked and un-exploited. Not all of that is down to poor memory safety of course, but it's a category of vulnerability that is massively increased in both surface and risk by choosing to write C.
Choosing Rust alone might be virtue signalling, but choosing a memory safe language is just pragmatic.
So magically the Rust was just as fast, but much more readable and when a junior (or an LLM) modifies it slightly so that the output container is bigger it won't suddenly segfault due to that scary in-place conversion loop now being a bounds miss, the Rust won't attempt the in-place conversion now that it can't work.
Firstly the obvious, LLMs aren't perfect yet, they still make mistakes.
But even if they could achieve safe C by asking them to "Write Safe C, Make no mistakes", there would still be a significant benefit to achieving safety by using Rust or a memory safe language.
LLMs work best when they have a combination of clear objective functions and guardrails. In this case, the compiler acts as a guardrail to keep it safe while trying to solve the problem that needs solving.
Having a compiler step prevents the LLM taking a "shortcut". Despite models improving, they will still take shortcuts, sometimes absurd ones, to meet some definition of a "job done".
The other massive benefit is cost and speed. Having an LLM analyze and reason about the safety is expensive and wasteful. Having this done at compile time is cheaper and quicker. The earlier in the feedback loop, the cheaper it will be.
Save your tokens for "real" work, not stuff you can check at compile time.
Quite the opposite. Outside of a couple of very specific kind of cases (for example working with microcontrollers not supported by Rust toolchain), there is no good reason to choose C when you could choose Rust.
Choosing C over Rust means throwing away the memory safety features that Rust gives you for free. And for what? There is just no upside to choosing C in the vast, vast majority of cases.
Rust protects you from a whole class of bugs (borrow checker) and lets you enforce almost as many invariants as you chose, through the type system.
LLM are just as bad as humans at enforcing/tracking ownership and invariants.
We maintain two code bases; one is TS and the other Rust.
Both are by now written foremost by agents (since August 2025, I'd say).
We had numerous non-(business)-logic bugs in the TS code base over this period.
Zero such bugs in Rust. Because the compiler catches them for us. All bugs we had in that code where actual logic bugs. I.e. the spec already had the bug or contained an oversight.
Zero.
We have since started rewriting the TS code base in Rust and will likely switch over in the next three months.
Seems like just virtue to me. The guy who volunteers every week to pick up garbage from the beach isn't virtue signalling, he's just virtuous. The guy who came once, with a film crew and left once they'd got the shots they wanted - that is virtue signalling. They're both shown in the film, but only one of them actually does the signalled virtuous activity when the cameras aren't rolling.
You could argue that RIIR was conducted as virtue signalling if what we saw was one of those translations smeared in unexplained unsafe blocks, with rats nest logic that no human is going to untangle. But that doesn't seem to be the case here.
Also, we have LLMs now. Rust should be the default for many things.
Or C Or Go Or ... Its like people can not look past one language, to understand that with LLMs, a ton of languages gotten way more easy.
Personal experience that running a few subagents parallel with Rust, just slows everything down to a crawl, even wit ccache and a ton of other tweaks. As long as your codebase is a few 100k lines, Rust is ok. But start going in the 500k, 1 million... starting to get C++ flashbacks where your spending more time waiting on the compile jobs, that fight each other for resources then actual testing.
Until Rust can fix their slow and resource munching compiler, its been off the menu for me. Ended up having everything in C and the difference was very noticeable.
the true performance hog is like sand, spread across the system, a little bit in every place.
Oh, and they can be annoying to refactor later on.
That and WinForms absolutely sucked compared to Swing. Layout options, tables/grids, and trees in particular were very poor in WinForms. Not to mention custom control development was far better in Swing than in WinForms. It was annoying because the one thing I’d expected to be better with .NET was the desktop UI framework.
The number of use cases where you actually can move just a small part of the program to C++/Rust and that solves performance is actually really small. Basically highly numerical things like AI or SMT solving. Even supposedly IO bound things like Django tend to be quite slow in Python.
Somewhere in your code is a little whammy where someone invalidated a bunch of tree nodes which took about 8 nanoseconds and caused the layout engine to now do tons of computation that it didn't have to do before. No profiler in the world is going to save you from this problem, it's going to tell you that the problem is in the layout code. Well duh, thanks for that, of course the compute is in the layout code, it's always in the layout code, all we do is layout and draw. So I have to find the 3 nanoseconds where somebody invalidated something that they have no business invalidating because it's wrong. And the way you fix that is [to have a sense of how to check that you're invalidating the right thing, regression testing, visualizations, logging, planning] and it could be literally 4 or 5 instructions dirtying the cache and that's not going to show up in a profile.
[paraphrasing; Casey: if you've developed the whole browser without caring about this, at the end you're going to find it very slow and not be able to squeeze any more performance out of the layout engine? Rico: Right, this is not something you can fix at the finish line, it needs a plan]"""
- Rico Mariani, interview: https://youtu.be/48Rig6v-xYU?t=3615
Most often, Python is enough.
But if you can optimize C, most often you can also optimize Python.
I have a SLAM implementation in pure Python+Numba where all points/keyframes are kept in a single flat table, no allocation.
And something tells me C# and Java could have gotten 90% of the improvement without any rewrite. I'll have to try later today.
Taking python as an example, one could use benefit of hindsight and make better decisions from the start ( offloading slow parts to C binaries, better DS decisions, eliminating bloat etc.. ) if they rewrite the same app in Python. This is kind of what happens when a program gets rewritten to another language ( Rust ) - better decisions are made from the start and less bloat is copied over.
Yes, obviously there are exceptions to this. But most of the time it is the choices we make that make the program slow and not the language itself.
It used to be that rewriting programs were almost always a dumb idea due to how much effort went into it - see: https://www.joelonsoftware.com/2000/04/06/things-you-should-... . But AI has made this argument less compelling imo. I now regularly rewrite big chunks of programs with various end goals given to the agent.
Rust's async situation is still a pain in many ways.
But throwing Rayon at something often results in very reasonable parallel performance gains without cluttering things much. It usually won't get you to an optimal solution, but it's good for 80% with 10% of the pain.
The performance oriented (data plane) work happens on dedicated, cpu-pinned threads and sockets outside the tokio runtime. The control plane work happens in tokio async. Interaction between the two is tricky. But decreased latency and increased throughput is valuable. And it's a complex server, so we can't really try too many approaches.
It certainly doesn't help that the data structures are, by necessity, a cephalopod that have to be used across threads.
Everything wants to push you down the path of using `ARC<Thing>` even when `Thing` is immutable or the lifetime can be mostly guaranteed.
Here's an example of that problem. Let's say I want to do 2 things concurrently against the same data set. I might want to write code that looks like this:
let v = vec![1, 2, 3];
let taskA = tokio::spawn(async {
println!("Here's a vec: {:?}", v);
});
let taskB = tokio::spawn(async {
println!("Here's a vec: {:?}", v);
});
tokio::join!(taskA, taskB);
But that immediately gets you in hot water because "async block may outlive the current function, but
it borrows `v`, which is owned by the current function"Now, you and I can clearly see that the async block does not, in fact, outlive the current function. However, AFAIK, there's no real way to convince rust that that is the case.
So now even though `v` is immutable, making this a thread safe operation, we need to introduce unnecessary concurrency constructs or break out unsafe in order to force the language to recognize that "Yes, you can trust me".
For rust to actually be fast with concurrent operations, it needs to be smarter about lifetimes in terms of async.
I thought we as an industry had hopefully moved past "async == magic code-go-fast sauce", but apparently we have not.
As much as Go annoys me, you're right there as well. I have to admit that Go did "solve" the make-concurrency-and-parallelism-accessible (and relatively safe) space in a way that very, very few other programming languages did (and none that people widely use).
Loop-blocking-as-backpressure is sometimes the right move, but only rarely. If you can isolate event loops for specific workloads (e.g. some shameless self promotion, releasing in PyPi this week: https://github.com/zbentley/async-anywhere/blob/main/src/asy...) that becomes a more tractable approach.
Java already did, especially now with virtual threads. Now other JVM languages can also get this benefit.
I'm not necessarily a "statically link all the things" zealot, but I think that pattern definitely has a place where problems like yours often occur.
The port was pretty direct, function for function. It was even line for line where language and library differences didn't offer an easier way. I was just trying to see if Python was so slow that we couldn't consider using it in production, and this was the most speed critical batch we had.
I assumed the speed difference was a bug that was skipping work, but that seemed unlikely because the output was correct. It turned out to be a bug in the C++ code that was needlessly reproducing work (an issue with cache keys). The bug was extremely subtle. When I fixed the C++, there was very little difference in speed as the batch was I/O bound when the cache was working.
So, adding to your point, sometimes you can greatly improve speed by rewriting in a slower language, even without performance in mind.
But also technically I think your point still stands. Because rewriting it helped you find a defect in the original. Which did improve performance of the original.
It’s quite interesting the two implementations performance was so close in the end. Do you consider one implementation “better” for non-performance reasons? Maybe one type of dev is easier to find. Or one language is easier to create and maintain correctly behaving programs in your environment?
Hiring devs who already knew Python was not really an option in 1997. But we quickly found that there was not much difference in time to ramp up a C++ developer on our C++ codebase vs. ramping up a developer on Python plus our Python codebase. It was just a matter of finding developers who were happy to learn a language they may or may not have heard of, but had likely never looked into.
I was not there for Python 3, but I was at a larger place that had ~2 million lines of Python 2 code when the migration happened. It was much easier than I had expected. The two key differences from other stories I was hearing was that were a lot of automated tests (nearly 100K of them), and we had someone who was very good at writing parsers. He spent a few weeks automating the changes and getting tests to pass, and the night he ran the final conversion was remarkably clean. We never even used `six`.
One of the problems, for C, is the use of . to access a field via a variable, and -> to access a field via a pointer. To switch between a pointer and a variable in a struct means you've got to re-edit large quantities of code everywhere. The result is just too tedious.
This was the motivation in D for using . for both. It turns out, it is completely unnecessary for having both . and -> as the compiler semantic pass can trivially figure it out. Eliminating this issue makes for much easier redesign of a data structure.
My mind equates -> to "this could be NULL" without ever looking at the function signature.
It is way more of a pain in the ass for refactors than = vs := though.
For me that's definitely a bad thing. It's the reason I don't like Rust syntax, they make you write everything out even if there is no possible way to misinterpret the code. And they never do things like Zig enum variant shorthand because syntax sugar is evil. Maybe they're just diabetic.
Not really Go in general, though. It’s mostly disappeared from my personal projects, in part because of their matching allergy to syntax sugar. I am incredibly tired of writing “if err != nil” blocks, and I don’t understand why there isn’t some kind of “if this function returns a non-nil error, return zero values and the error”. If only I could get something better to make a static binary. By which I mean “I like Clojure and refuse to learn SBCL because… reasons”
#[derive(Debug)]
enum E { A, B, C }
pub fn main() {
use E::*;
let x = B;
println!("{:?}", x);
} struct S {
int a;
int f(); //getter
void f(int i); // setter
}
void test() {
S s;
int i = s.a;
int j = s.f;
s.f = i;
S* ps;
int k = ps.a;
int l = ps.f;
ps.f = k;
}
i.e. the field can be replaced by a function and the usage of it would not change.- It does not run code behind my back when I access a field.
- I see when a pointer is used, so the syntactic distinction between -> and . is important.
Being able to change this without changing these little things is far less important to me than being able to understand important properties of the code just by looking at it.
-> just… isn’t. Acknowledging it’s a pointer with a different accessor is just not really that important. I mean, in some specific cases it might be, but in general it’s not.
Point in case: go?
We converted a Python pipeline to Rust and it's 50x+ faster depending on the customer.
This was mostly important for tasks like backfills where you're processing hundreds of times more data than usual.
"When in Rome, do as the Romans do"
Doesn't seem a recipe for success
https://simonshine.dk/articles/nix-appimage-when-musl-is-not...
I was thinking of maybe turning it into a minimal UI framework. I noticed that Quickshell apps in Hyprland are comparatively very large so something lighter weight might be useful.
Rust itself had an understandability issue until LLMs came along and started speedrunning parts of the Rust development process, so this argument is language AND time immaterial.
Py2many is an implementation of these concepts.
Developers rewrite code in rust for memory safety, not speed.
* Memory safety
* Performance
* Logical correctness
People definitely rewrite in Rust for speed. To be honest I would say memory safety has been overegged as an advantage - yes obviously you want memory safety, but I think some people think it's the only advantage Rust has, when logical correctness (due to the stronger type system) is definitely in the same league.
But in many cases a rust version already exists (like for tokenization etc.). I wouldn't advise to write it yourself if a supported repo is already doing it.
TCC even has a —script mode for C.
Then absolutely rewrite it so that it uses Tauri instead. Which takes your executable from 300MB to about 5MB for something that actually does something meaningful.
It's certainly still "replace the slow (but really, inefficient, not just slow) parts", but instead of 5% it's 98%.
Rust here was mostly because they wanted to link to it. It has some benefits by itself, but the real killer feature was the e2e tests that they had for the effort.
Do we actually see this? I mostly write in a dynamic language (Elixir) and it generally one-shots features with no errors. I also have an extended project in zig and it rarely if ever writes spatiotemporal memory errors and doesn't segfault unless I'm miscompiling targets or doing something truly cursed (pointers crossing ABIs in a dllloaded shared library)
In the app you could refactor the slow code, or optimise the run the time without introducing Rust.
You could run an optimised micro service.
Finally it is most likely to be an issue with database transactions which can be solved with better queries, indexes, separate read/write, caching, batching, and so many other techniques to avoid non critical blocking.
It had some warts, but IMO was far more easy to solve than doing something like the swift project. In hindsight apple should've invested into Rust and continued to improve Objective-C as an applications programming language.
I noticed something interesting about LLMs: if you ask them to create a Rust inference tool, it may use Rust for the glue code, but it'll stick to Python for everything else. LLMs are just like us: they don't like wasting time rewriting everything in Rust, especially when they know that the most important libs, say PyTorch, aren't written in Python.