34 comments

  • zodwick 8 hours ago
    I would like to argue that one could make most codebases 50% faster if rewritten from scratch with performance in mind even in the same language.

    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.

    • WalterBright 3 hours ago
      Over the many years I was writing code in C, I noticed that the original program design and data structures were very persistent, i.e. they were never reorganized. I suspect the cause is the tendrils of those choices found their way into everything, so reorganizing it was thoroughly impractical.

      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.

      • metaltyphoon 2 hours ago
        Rust offers this via de Deref trait
      • everforward 2 hours ago
        I actually don't hate that part of C. You have to acknowledge it's a pointer with a different accessor. I liken it to = vs := in Go. It's an unnecessary semantic, sure, but it elevates a technical detail to be part of the syntax of the language. Go has caught me a couple of times when I forgot I had the same variable name in scope already (e.g. opening a second file descriptor and trying to name it "fd" again).

        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.

        • WalterBright 29 minutes ago
          There's one more aspect to it in D:

              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.
        • tancop 2 hours ago
          > it elevates a technical detail to be part of the syntax of the language

          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.

          • everforward 33 minutes ago
            Totally fair, I get that. I’m also not a hardened C dev, so maybe it would annoy me at some point. I gripe about Go’s assignment operators from time to time, but I like it on the net.

            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”

    • rented_mule 6 hours ago
      I rewrote a C++ batch process in Python 1.4 (this was 1997) and the Python version was ~10x as fast.

      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.

      • drfloyd51 5 hours ago
        To be technical about it, the Python program didn’t match the behavior of the c++ program. ;)

        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?

        • rented_mule 3 hours ago
          The Python version was far easier to maintain and add features to. We kept it and rewrote other code in Python whenever we did significant work on it. All new back-end code was also written in Python after that.

          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.

          • asdff 2 hours ago
            Were you around for migration into python 2 or 3?
    • rafram 7 hours ago
      See uv - replacing pip with a rewrite in Rust was a good stunt, but the big performance gains came from eliminating dynamic features (uv doesn’t allow packages to execute code when installed) and I/O (better caching and parallelization).
      • chowells 3 hours ago
        I think the biggest win of going from pip to uv is that breaking your python environment no longer breaks the tool to manage your python environment. Pip was always fragile in that you could carelessly use it to break a library it is depending on. (Yes, there are ways to avoid that - but they require not being careless.)
        • Joker_vD 3 hours ago
          I once, on a fresh Ubuntu install, did "apt install python-pip3", and then "apt install python3.8" when I realized I actually needed Python 3.8. The pip3 complained that it was outdated and suggested a command to run to update it. Naturally, I ran it, and it completely broke apt, it couldn't even do "apt list" never mind intalling/removing packages, so I had to rollback the VM to fix this bullshit. Wonderful, 10/10 DevEx.
          • zbentley 38 minutes ago
            I'm not sure that's a compelling indictment of Python specifically, but you definitely make a good case for tools that are often needed as prerequisites for using other tools (package managers, decompressors, the basic drivers needed for HID, slow networking, VESA graphics, storage) being distributed in a self-contained way.

            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.

      • zodwick 7 hours ago
        Yes exactly, I think this article explains it well :- https://nesbitt.io/2025/12/26/how-uv-got-so-fast.html
      • dgacmu 6 hours ago
        Though to give credit where it's due, it's a lot easier to parallelize things well in rust than in python. The coarse-grained download parallelism is easy in both, of course (though with higher overhead in python), but the more fine-grained solver parallelism favors rust (or c/c++ but let's not do that).
        • jeffbee 6 hours ago
          Every cursed rust application I've been hired to fix has been diagnosed as spending 90%+ of its time pointlessly jumping tokio threads because someone thought that async means fast. I give these 10x throughput boosts by removing concurrency or, sometimes, just rewriting them in Go.
          • dgacmu 6 hours ago
            You're talking about concurrency and I'm talking about parallelism. :-)

            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.

            • zbentley 36 minutes ago
              I interpreted GP as talking about maintaining Rust code that was written with performance in mind by people who were not familiar with the difference, and who shot themselves in the foot as a result.
            • jeffbee 5 hours ago
              It depends on what you are going for: service latency, or throughput. Rayon's work stealing is inappropriate for any throughput oriented work and questionable for the majority of latency sensitive services. It does have a niche but it's not the first thing I would reach for. Unfortunately it IS the first thing Claude reaches for.
          • cogman10 2 hours ago
            Rust makes it pretty hard to do fast async, IMO.

            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.

          • toast0 3 hours ago
            That's why the rust server I work on is an unholy mix of threads and tokio...

            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.

          • zbentley 34 minutes ago
            Absolutely. I have the exact same problem dealing with Python people who have done the same thing. "This is all modern, async python and therefore can scale. What do you mean our event loops are routinely blocked?!"

            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).

    • Eridrus 29 minutes ago
      You're right, but sometimes you do the 50% performance improvements (over time, 10% here, 5% there) and you're still not happy.

      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.

    • kleiba2 4 hours ago
      A good point in time to mention Casey Muratori: https://www.computerenhance.com/p/clean-code-horrible-perfor...
    • yjftsjthsd-h 3 hours ago
      Or, as I have seen it succinctly put: The value is as much a Rewrite in Rust as a Rewrite in Rust.
    • brunoarueira 5 hours ago
      About python, I did exactly small things and optimized a data pipeline really well https://brunoarueira.com/blog/optimizing-19-million-rows-pip...
    • nicoburns 7 hours ago
      I mean, it's definitely both. Of course there can be algorithmic improvements, but a like-for-like rewrite of Python code into Rust can often be 10x faster.
      • rapind 6 hours ago
        Don't forget 10x iteration time and deploy time due to building on large projects. Still can be worth it, but I highly recommend build costs (CPU, RAM, Disk, Time) are considered in a rust rewrite decision. I'd even architect around it from the start as it can really add up.
      • zodwick 7 hours ago
        Depends on the application. Tbh the comparison btwn python and rust is kind of dumb. But for the sake of argument - I don't think most well-written Python codebases can get 10x faster by using Rust. Bit faster ? sure maybe. Remember Python uses C under the hood. Unless there is a shit ton of looping or weird unrealistic conditions i don't think this is true
        • pastel8739 4 hours ago
          I think it totally depends, I’ve seen huge (100x) speed ups by moving a pure-python CPU heavy task to a compiled language. If you’re using something like numpy already to run compute natively, then yes it’s probably much more difficult to get gains.
  • novok 1 hour ago
    This is a big reason why I miss Objective-C. It was fast compiling, strongly typed, small binary size, decent debugger, good multithreading with GCD, a fully dynamic runtime, let you seamlessly drop to C++ for that 5% of code runtime boost if you needed it, a well designed batteries included standard library set in the iOS days it was prime in and on average a runtime speed that was between Java and C / C++ if you didn't bother to optimize that 5%.

    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.

  • ThouYS 9 hours ago
    neat, but in my experience bottlenecks that you could solve this way are low hanging fruits and optimized away quickly.

    the true performance hog is like sand, spread across the system, a little bit in every place.

    • jodrellblank 7 hours ago
      """If you're looking for the next win, you don't have a hotspot. The CPU profile might look even-Stevens across the board. Let me give you a really simple example of this, I used to work on the [Edge] browser and you could find yourself with a significant regression one week and you're using way more CPU, and you look what the functions are and it's the same functions as always. It's layout and it's style computation, and that code hasn't changed a byte. It's the same excellent layout engine, it's the same excellent style engine, and yet the profiler will tell you you're spending way more time in layout. What's happened?

      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

      • Veserv 1 hour ago
        That is just due to not using good performance observability tools. These sorts of problems are easy to see with a full instruction trace that uses good, standard visualization on a problem case.
        • novok 1 hour ago
          What are your favorite perf observability tools.
    • IshKebab 8 hours ago
      Exactly my experience. You can make Python code faster by profiling and improving the hotspots, but once you've done that it will still be 10x slower than C++/Rust at least, and that slowness is evenly spread through the whole program.

      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.

    • szundi 8 hours ago
      [dead]
    • sham1 8 hours ago
      A lot of lost performance also comes from things like the architectural decisions and technical debt that would pile up over time. These considerations are also like sand in that they're coarse, rough, irritating, and they get everywhere in the codebase.

      Oh, and they can be annoying to refactor later on.

      • embedding-shape 7 hours ago
        Using the right data structures for the right usage later on is like half the battle. People get really annoyed when you show them a Python program that is faster and shorter than someone's C# program, merely because they used the wrong data structures for how it's being used.
        • kamma4434 6 hours ago
          One of the nicest things of Java is that a list is a List<>. You can start with the default ArrayList or use a ton of other variants, or write your own, and all that changes is one line of code
          • bartread 2 hours ago
            One of my biggest beefs when moving Java -> C# back in 2004 was the paucity of collections in C#/.NET. There was C5, which was good, and the framework itself did eventually improve a little, but it was still no match for the Java standard library + Apache Commons Collections.

            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.

            • kamma4434 2 hours ago
              Ow… Swing! I can definitely live without!
  • hendler 12 hours ago
    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.
    • Jnr 4 hours ago
      Exactly, seeing the AI vulnerability hunting apocalypse happening around, I would rewrite in safe Rust to avoid certain types of security issues. Speed and low memory usage is just another bonus.
  • dejaydev 1 hour ago
    I worry that this just adds complexity to most projects. The example in the readme is a Python function find_duplicates and poses to rewrite an implementation of Levenshtein in Rust. How do I know it's not faster than just switching to maintained software like RapidFuzz? Why would a maintainer want a dependency they can't understand in the hot path of their project?
    • dalemhurley 1 hour ago
      This is a great point.

      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.

  • buryat 2 hours ago
    First of all, start with the measurements methodology, making sure that you're measuring a thing that actually matters for end users in all the various configurations on a setup that matches closely your production setup, otherwise results will never be completely conclusive unless you're trying to optimize a small piece and it gets flattened into noise on top of the overall picture. Significant optimizations are always difficult because they cut through lots of dimensions and limitations that the older system over fit into or started hitting them, and those limitations usually these days go all the way into how concurrent systems work which influences everything else that the program might be doing. Saying it as some one who fights 1ms network latencies and L3 caches behaviors
  • osigurdson 6 hours ago
    I did an experiment to see how small and efficient I could make a desktop Linux app. One thing I learned is GPU adds a lot of memory overhead without much benefit for very basic apps.
    • sshine 4 minutes ago
      I did a similar attempt to produce small AppImages for GTK applications where static binaries are not an option. With a bit of recompiling dependencies with different flags and trimming i18n away, I went from 897MB to ~20MB.

      https://simonshine.dk/articles/nix-appimage-when-musl-is-not...

    • micahcc 4 hours ago
      Only put it on the GPU if you have thousands of nearly identical operations to do
      • osigurdson 3 hours ago
        Agree. I learned quite a few things in this exercise, actually. Another one is that conventional font rendering uses a lot of memory as well. Link below if anyone is interested:

        https://github.com/osigurdson/mib

  • zamalek 2 hours ago
    The reason rust is so tied to all the AI rewrites is because we see that the power of AI improves when the task has stronger verifiability. A stronger example is reverse-engineering: you have the final machine code to verify against. Performance of the final binary is still a bonus, but it's the strictness of Rust that makes it great for AI.
  • the_arun 5 hours ago
    Java - “1.18s, 3× (11× on the function; the rest is JVM startup)” - why are we including JVM start up? Can’t we assume Java is already started? We don’t start JVM for every function. Right?
  • alexfromapex 5 hours ago
    I didn't realize until I rewrote in Rust that psycopg2 is about as fast in Python as Rust database calls because it's all compiled in C. I had to do the full re-write because my code was going to live on customer machines and I didn't want them stealing IP. The speed, stability, and security boosts are just added bonuses.
  • diegocg 13 hours ago
    Better yet, stop writing large codebases in lenguajes that will have performance troubles.
    • tripledry 12 hours ago
      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.
      • the8472 7 hours ago
        Python and Ruby are single-threaded (yesyes, there's noGIL python now), which in turn means they're deployed as multi-process services, which means they must be stateless, which means there is a lot less you can keep in-memory and need to offload to external stateful systems. And that's how you get your bad architecture.

        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.

        • graemep 2 hours ago
          > deployed as multi-process services, which means they must be stateless, which means there is a lot less you can keep in-memory and need to offload to external stateful systems. And that's how you get your bad architecture.

          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?

          • eszed 43 minutes ago
            > 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.

          • asdff 2 hours ago
            Fields like stats or data science are often heavy computation in python. Even R. Single thread does not matter, because this python run might be one of some thousands+ you have a cluster chewing through 1 per cpu core.
      • chrismorgan 11 hours ago
        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.

        • kamma4434 6 hours ago
          True, but scaling out helps with more than load sharing. Singletons are always a risky architecture - what happens when they go down?
          • chrismorgan 5 hours ago
            They’re risky in that sense, but their very simplicity makes them less subject to other sorts of failures—distributed systems have more and more complex failure modes.

            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.

      • andyferris 11 hours ago
        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).

      • FartyMcFarter 12 hours ago
        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.

        • rhdunn 10 hours ago
          Libraries generally write hot code in languages like C, C++, or Rust and bind that to Python (PyTorch, etc.) or provide bindings/wrappers around libraries in those languages (SQLite, PostgreSQL, etc.).

          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.

          • fiedzia 4 hours ago
            > 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.

            • rhdunn 3 hours ago
              As always, it depends.

              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.

        • cadamsdotcom 11 hours ago
          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 11 hours ago
            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.

            • cadamsdotcom 10 hours ago
              We all have different lenses on the makeup of the entire set of software out there, it's likely you're coming from that experience and the other post was coming from experience mostly with i/o bound software.

              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 ;)

              • pessimizer 10 hours ago
                This conversation is pointless. The answer to whether some people see actual problems in the real world© with using very slow interpreted languages is "yes."

                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.

                • pdhborges 8 hours ago
                  The easiest way to have an I/O bound workload is to use fast languages.
      • xtracto 7 hours ago
        I recently built a small nextjs/node application that basically makes like $50 usd monthly. Initially built as a PoC, I wanted to place it in a vps so that I didn't have to maintain it in my home laptop, and also because I wanted to move it to a Europe location for better business performance [im in mexico and latency is high].

        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.

        • embedding-shape 5 hours ago
          What exactly is it doing during these 2 seconds? What did it stop doing for those 2 seconds to become whatever it is now? Did Claude use a different (more fitting) design, architecture and data structures perhaps? Did Claude also write the initial version?
          • xtracto 57 minutes ago
            Processing input from a websocket, and then doing some calculationsand http requests [which need low latency, hence the Europe server].

            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.

        • owebmaster 4 hours ago
          Was it Claude that made the terrible choice of using nextjs in the first place?
      • austin-cheney 9 hours ago
        Maybe. When I stress test my JavaScript application I can push up to 6,000,000 WebSocket messages per second in Node (C++) but do experience some amount of memory instability. When I run the same application on Bun (Rust) it’s not as fast but it’s extremely stable.

        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.

      • afavour 8 hours ago
        In my experience memory issues are more common. The way JS stores objects in memory is fundamentally inefficient (though it’s deliberate, it’s why you can do object.propertyIJustMadeUp = true on anything, any number can be a float, etc) and if you’re moving a ton of data it can cause issues eventually.

        The only JS-native answer is to use typed arrays, which is using a sledgehammer to crack a nut.

      • fiedzia 9 hours ago
        Mostly because anything that needed to be fast already was written in a language that allows that and most of web/app development focuses on shuffling small amounts of data around. Also pure Python is worse than node in this aspect. Still, there many non-trivial cases. There is a reason most of infrastructure moves to Rust. I've seen poetry spending 30min (!) on dependency resolution once. Test runners and some background/nightly data processing if often first place where you realize you may want to rewrite.
      • IshKebab 8 hours ago
        Yes. Most often with Python. People think performance isn't going to be a problem and by the time it inevitably is, it's far too late to use a better language. (At least before AI.)

        I've seen this at almost every company I've worked at.

      • anatolii1309 9 hours ago
        [flagged]
  • tialaramex 10 hours ago
    Note that this strategy only works if 5% of your software is the problem - because of Amdahl's law.
  • perdy 12 hours ago
    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.
    • krmmalik 9 hours ago
      How do you feel about your decision now that this has been done? Was it worth it or not?
      • perdy 7 hours ago
        For the parts that scale, yes. I build a CI step for measuring the performance with Callgrind since last pure-python release, and we achieved good numbers: matching the last of 200 routes dropped to about half the cycles and serializing a large JSON to about 25% less. So it pays off for work that grows with the input.
  • ezbie 6 hours ago
    I dont get the point of this.

    Developers rewrite code in rust for memory safety, not speed.

    • iagiagiag 1 hour ago
      I recently did it only for speed honestly. Python is quite slow in many cases, like a small operation on millions of lines of text. I tried the rust version and it removed that bottleneck, it's quite easy with AI. It's mostly for manipulation of strings, for math we already have numpy, numba, pytorch etc.

      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.

    • jeremyjh 1 hour ago
      Python and Node are already memory safe. If that were the only thing that mattered, Rust wouldn't be a thing.
    • 1970-01-01 3 hours ago
      As we just saw in the MS outage, making it run faster might be introducing race conditions that were previously shadow conditions. You have the correct take. Rewrite the parts that are bad, not the parts that are slow.
    • IshKebab 3 hours ago
      Rubbish. There are at least three big reasons to use Rust:

      * 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.

    • caymanjim 1 hour ago
      As far as I can tell, the only reason people rewrite things in Rust is so that they can make HN posts about rewriting a thing in Rust that didn't need rewriting in the first place.
  • adsharma 6 hours ago
    Write in a variant of python that can be machine translated to rust. If you're using agents you might need an intermediate step.

    Py2many is an implementation of these concepts.

  • vkaku 6 hours ago
    There is the other argument to rewrite it in something - delayer complexity where it doesn't solve an understanding problem. This has led to a phenomenal code decrease where rust primitives tackle a ton of structured case handling while keeping code simple and readable.

    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.

  • afdbcreid 12 hours ago
    Funny that this codebase is 62% Rust, 9% Python. And I'm a huge Rust proponent.
    • stavros 8 hours ago
      Why is that funny? He rewrote the slow 9% in Python.
  • Bolwin 8 hours ago
    The results section feels a bit like a joke. They rewrote C and C++ to Rust for performance?

    And something tells me C# and Java could have gotten 90% of the improvement without any rewrite. I'll have to try later today.

    • stackskipton 7 hours ago
      It looks like it finds hot paths, rewrites them into Rust so you can just insert them into Python code vs rewriting everything into C# or Java.
  • raincole 8 hours ago
    I'm... not so sure why you need a repo for that. It's almost 2027. You can literally just type "profile this app and find out the performance bottleneck" then "rewrite it in rust" in your agent TUI...
  • Almondsetat 8 hours ago
    This way the trickiest parts of the codebase get reweritten in a language you don't even know...

    Doesn't seem a recipe for success

  • solyin 8 hours ago
    Nah. Do it in Swift.
    • Kuyawa 6 hours ago
      Exactly, if you are on Mac/iOS there is no better language

      "When in Rome, do as the Romans do"

  • efficax 6 hours ago
    ffi boundary often means you lose any gains from rust to packaging up the data and shipping it via c structs back and forth between the language runtime and rust
  • Dwedit 7 hours ago
    This looks very AI-generated.
  • anttiharju 13 hours ago
    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 12 hours ago
      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 12 hours ago
        wasm compiled to native is only ~62% slower (LLVM) and only 3% slower for non memory bound operations.
  • TheRealPomax 3 hours ago
    Unless your app uses Electron.

    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%.

  • tomp 8 hours ago
    Or just rewrite in Numba.

    Most often, Python is enough.

    • fiedzia 8 hours ago
      Hell no. Rust is easier to read, write, maintain and reason about. Way more people know Rust than Python/Python internals/Numba interactions. Numba will either get you relatively low gains with little effort, or push into territory very you write code few people will understand, because reasoning about its performance requires deep knowledge of Numba and Python internals. Rust gives a lot more ROI and looks more like Python.
      • odiroot 7 hours ago
        "Easier to read" is really doing a lot of work in this statement. Highly debatable.
        • simonask 7 hours ago
          Harder to read, easier to understand.
    • toxik 8 hours ago
      Not my experience, actually. Numba and other such techniques (like having some hot paths in C/Rust/whatever) works, but eventually just allocating and deallocating Python objects starts to become a measurable problem. Especially if you have any kind of fancy metaclasses, descriptors, etc. "So don't"--ok, so give up Python's dynamic features? Why bother at that point. Now it is so cheap to write code anyway, why bother with Python at all? Have a design document in actual English.
      • tomp 7 hours ago
        No language will save you from inefficient memory allocation patterns.

        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.

  • fukaiall 5 hours ago
    I don’t mind rewritting in any language. But the one in Rust looks more like led by asshole-like cult and for showing off to others than pure engineering purposes.
  • searealist 9 hours ago
    This cope was common 20 years ago with Python. It rarely worked out. It's rare that 5% of your program is taking up that large a percentage of your execution. It's usually much more spread out than that.

    Also, we have LLMs now. Rust should be the default for many things.

    • benjiro29 8 hours ago
      "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.

      • jghn 8 hours ago
        Didn’t you know that rust is the awesomest most ultimate language ever!?!
  • heybax 2 hours ago
    [flagged]
  • arbor-group 6 hours ago
    [flagged]
  • Prospernwo 11 hours ago
    [flagged]
  • manfred_singer 12 hours ago
    [flagged]
  • egorfine 11 hours ago
    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.

    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.

    • eterm 11 hours ago
      > 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 10 hours ago
        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.

      • curt15 9 hours ago
        In the age of machine-generated code, why not ask LLMs to write "safe C"?
        • eterm 9 hours ago
          You've received downvotes, but I'll do you the kindness to actually answer you.

          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.

    • QuantumNomad_ 11 hours ago
      > 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 11 hours ago
      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.

    • tialaramex 7 hours ago
      > virtue signaling

      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.

    • jph 11 hours ago
      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.

    • booi 11 hours ago
      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.
    • IceDane 11 hours ago
      > 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.

      • uecker 6 hours ago
        I found that you can not build good abstractions in C is mostly a myth.
        • preg_match 2 hours ago
          You can build okay abstractions and then to maintain them you have a pinky-promise system so it doesn’t matter. You basically can’t build any abstraction in C because you can’t make a guarantee about… well… anything. Anyone at any point can just break your abstraction. And they will. At 100 lines of code maybe you can see that they don’t, but most projects are bit larger than that.

          Even very basic abstractions possible in basically every language, like say a type that holds JSON text, is not possible in C.

          • uecker 2 hours ago
            You can build types around structures and access them via wrappers. This works perfectly fine for many abstractions. Sure, one can break those abstractions, but not accidentally, and this is true also in other languages.

            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.

    • jstanley 11 hours ago
      Rust's incredibly strict and detailed static analysis, while a huge headache for human developers, is really useful with LLMs.