| ▲ | Fast-Anything: Don't rewrite it in Rust. Rewrite the 5% that's slow(github.com) |
| 35 points by BaselAshraf81 7 hours ago | 23 comments |
| |
|
| ▲ | diegocg 2 hours ago | parent | next [-] |
| Better yet, stop writing large codebases in lenguajes that will have performance troubles. |
| |
| ▲ | tripledry 2 hours ago | parent [-] | | Genuine question, is this a common problem people see out in the wild? In my dayjob(s) I've basically never seen major slowness that comes from using something like nodejs / python, the bigger culprits have been network / db / bad architecture or code. | | |
| ▲ | andyferris an hour ago | parent | next [-] | | Yeah, Python is one I where I find moderate amounts data can be a pain - I end up tempted to move CPU work to the database or precompute more things, and it’s hard to get the advantages of single binary programs (for deployment, startup time, etc). (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). | |
| ▲ | chrismorgan 34 minutes ago | parent | prev | next [-] | | Performance is broader than just slowness; it’s also CPU and memory usage, things which will force you to scale horizontally (multiple machines) much sooner. 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. | |
| ▲ | FartyMcFarter an hour ago | parent | prev [-] | | Yes. Python is usually 10-100x slower than languages like C, C++ or Rust. If your program is CPU bound, this shows up very obviously. If it isn't, you may never notice at all. 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. | | |
| ▲ | cadamsdotcom 35 minutes ago | parent [-] | | What you're saying is valid too; but, the post you're replying to implied most slowness is network (i/o bound) or bad architecture (accidental cpu bound, fixable by tech debt cleanup). | | |
| ▲ | FartyMcFarter 33 minutes ago | parent [-] | | That post was also asking if other people have seen language mattering. In the places where I've worked programs are often CPU bound. Places like these are why compiled languages are still alive and kicking. I'm not denying that domains exist where being I/O bound is a thing. For those cases Python can be a fine choice. |
|
|
|
|
|
| ▲ | hendler an hour ago | parent | prev | next [-] |
| It's also OK to rewrite in Rust because it's not just about performance. The fast part in other Python, Ruby, etc may be written in C/C++, or call an external library, and be the vulnerable part. |
|
| ▲ | perdy 2 hours ago | parent | prev | next [-] |
| We took this route in a Python web framework I maintain: route matching, JSON encoding, request body parsing, compression and some other specific parts moved to Rust with PyO3, everything else stayed in Python. |
|
| ▲ | afdbcreid 2 hours ago | parent | prev | next [-] |
| Funny that this codebase is 62% Rust, 9% Python. And I'm a huge Rust proponent. |
|
| ▲ | egorfine an hour ago | parent | prev | next [-] |
| What does %LANGUAGE% have anything to do with the goal? Totally same principles apply for any other lower level language: Zig, C. While Rust is awesome, a lot of times the only apparent reason to chose Rust over C is virtue signaling. |
| |
| ▲ | eterm 41 minutes ago | parent | next [-] | | > the only apparent reason to chose Rust over C is virtue signaling 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. | | |
| ▲ | tialaramex a minute ago | parent [-] | | In this particular topic (performance) Rust matters because it will deliver excellent performance. You could write a container -> map -> map -> container flow in fifty memory safe languages, but probably it would be a bit slower than the nasty hack you'd write in C to convert the data in place. Rust isn't, if you're intrigued you will discover that Rust 1) figured out that the two containers must be the same size in memory so it can re-use the original container and 2) did the in-place conversion even though that wasn't what you wrote, because it's faster. 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. |
| |
| ▲ | QuantumNomad_ 36 minutes ago | parent | prev | next [-] | | > a lot of times the only apparent reason to chose Rust over C is virtue signaling. 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. | |
| ▲ | virtualritz 32 minutes ago | parent | prev | next [-] | | That's a pile of bollocks. 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. | |
| ▲ | jph an hour ago | parent | prev | next [-] | | Today I added Rust checked arithmetic which detects and protects math bugs such as integer addition overflow and division by zero. 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. | | |
| ▲ | Conscat 25 minutes ago | parent [-] | | This is in the C23 standard library as well, just without nice sum types sadly. |
| |
| ▲ | booi 43 minutes ago | parent | prev | next [-] | | That's actually why we chose Rust over C at my new company, Virtual Signaling as a service™. We rewrite anything in Rust for companies looking to virtue signal. | |
| ▲ | jstanley an hour ago | parent | prev | next [-] | | Rust's incredibly strict and detailed static analysis, while a huge headache for human developers, is really useful with LLMs. | |
| ▲ | IceDane 44 minutes ago | parent | prev [-] | | > While Rust is awesome, a lot of times the only apparent reason to chose Rust over C is virtue signaling. 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. |
|
|
| ▲ | anttiharju 3 hours ago | parent | prev [-] |
| Hah, pretty neat! 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. |
| |
| ▲ | combobyte 2 hours ago | parent [-] | | Doesn't that kind of defeat the purpose? Compiling to WASM is going to erase any speed advantage you'd get from native Rust. | | |
| ▲ | himata4113 2 hours ago | parent [-] | | wasm compiled to native is only ~62% slower (LLVM) and only 3% slower for non memory bound operations. |
|
|