News for hackers. Stuff that matters.
Re:My negative views on Rust (2021) (2023) by IshKebab on Wednesday October 09, 2024 @04:38PM (#41792371)
So much to disagree with....

> In practice, people just want to be able to write a tree-like type without having to play Chess against the compiler.

Sure, Rust's strong encouragement of tree-structured ownership may be annoying when you try and make a spaghetti ownership soup, but it's not like it doesn't have upsides. Many people have written about how the ownership & borrowing rules lead to code structure that has fewer bugs.

> I think that if you rewrite anything from scratch with performance in mind, you’ll see a significant performance improvement.

Maybe, but I think this is missing the point. The "rewrote it in Rust and it's X times faster" stories are generally when people rewrite from very slow (Python) or medium fast languages (JavaScript or maybe even Go).

In those cases you can rewrite in Rust without considering performance and get amazing speedups. I recently did a straight 1:1 port of some Python code with zero extra optimisation effort and got a 45x speedup.

Sure I maybe could have got the same in C or C++ but there's no way I would have rewritten it in C++ because fuck segfaults and UB. I don't want to spend any more of my life debugging that.

> Rust has arrived at the complexity of Haskell and C++, each year requiring more knowledge to keep up with the latest and greatest.

I don't really know about Haskell, but I don't think Rust's complexity is anywhere close to as bad as C++'s. Even if it were it doesn't matter because in Rust if you forget some complex rule the compiler will tell you, whereas in C++ it will randomly crash but only in release mode after the program has been running for 2 hours. Totally different.

> The “Friendly” Community

Gotta agree with this though. The "we're friendly" thing is bullshit.

> Async is highly problematic

Also agree here. Async is a huge wart on Rust's otherwise relatively unblemished face. Big shame. Oh well. You can mostly avoid it, and there are some cases where it's genuinely good (e.g. Embassy).

> I feel like Rust is self-defined as a “systems” language, but it’s being used to write web apps and command-line tools and all sorts of things. > > This is a little disappointing, but also predictable: the more successful your language, the more people will use your language for things it wasn’t intended for.

I don't see why he's disappointed about this. Rust is great for command line tools and web backends.

> I think that the excellent tooling and dev team for Rust, subsidized by Big Tech, pulls the wool over people’s eyes and convinces them that this is a good language that is simple and worth investing in. There’s danger in that type of thinking.

Ok this guy is not worth listening to.

Re:My negative views on Rust (2021) (2023) by tptacek on Wednesday October 09, 2024 @05:00PM (#41792563)
First off, if you edit the "this guy is not worth listening to" out of your comment, you'll probably get better responses from people.

Second: I don't think this author disagrees with you that there are huge speedups to get from porting code out of Python. But you'd also get huge speedups porting to Java, and you wouldn't be in the business of managing your own memory lifecycles.

Re:My negative views on Rust (2021) (2023) by IshKebab on Wednesday October 09, 2024 @05:13PM (#41792696)
I don't think that was too harsh given that he's saying that everyone who likes Rust (an extremely popular language) is an idiot who has been tricked into thinking it's good.

How can you take opinions like that seriously? It's like saying "nah The Beatles weren't actually that good, everyone just thought they were because of their cool sunglasses".

It's patronising and illogical and I don't think it's worth listening to nonsense like that.

Re:My negative views on Rust (2021) (2023) by tptacek on Wednesday October 09, 2024 @05:13PM (#41792703)
He didn't say that at all.
Re:My negative views on Rust (2021) (2023) by IshKebab on Thursday October 10, 2024 @02:32AM (#41796152)
I literally quoted it:

> I think that the excellent tooling and dev team for Rust, subsidized by Big Tech, pulls the wool over people’s eyes and convinces them that this is a good language that is simple and worth investing in. There’s danger in that type of thinking.

Patronising and wrong.

Re:My negative views on Rust (2021) (2023) by al_potato on Thursday October 10, 2024 @09:57AM (#41798879)
I think they're squaring "simple" against "millions of dollars of investment." Some other languages are successful without that.
Re:My negative views on Rust (2021) (2023) by VeejayRampay on Wednesday October 09, 2024 @04:43PM (#41792418)
I'm curious what kind of code gets a 45x speedup by going from python to rust

and by that I don't mean the rhetorical or bait-style "i'm curious", no, the literal I'm curious, cause I'm trying to find use cases such as that these days and I'm often thwarted by the fact that for anything requiring remotely decent speeds, python most of the time already delegates to C extensions and so any rewrite is not as useful

Re:My negative views on Rust (2021) (2023) by jerf on Wednesday October 09, 2024 @05:23PM (#41792811)
"I'm often thwarted by the fact that for anything requiring remotely decent speeds, python most of the time already delegates to C extensions and so any rewrite is not as useful"

Be sure you verify this is the case for whatever you think it is, though. Pure Python is so much slower than compiled languages (not just Rust) that you don't have to do much percentage-wise in pure Python before you've badly fallen behind in performance versus the pure-compiled alternatives.

I think this is asserted a lot more often then it is benchmarked. I am reminded of the way people for a long time asserted that the performance of web languages doesn't matter because you spend all your time waiting for the database, so it never mattered. People would just whip this argument out reflexively. It turns out that if you take a non-trivial codebase written in such a language and actually benchmark it, it is often not true, because as applications grow they tend to rapidly outgrow "all my code is just running a SELECT and slamming the results with minimal processing out to the web stream". I hear this a lot less often than I used to, probably through the slow-but-effective process of a lot of individuals learning the hard way this isn't true.

I've seen a lot of Python code. Very little of it that was not "data science" was just a bit of scripting around lots of large C-based objects, such that Python wasn't doing much actual work. And even some of that "data science" was falling back to pure Python without realizing because NumPy actually makes that shockingly easy.

Re:My negative views on Rust (2021) (2023) by NoGravitas on Thursday October 10, 2024 @10:05AM (#41798961)
It would be interesting to me to look at something written in Python and rewritten in Rust with a 40x speed-up, and then rewrite it in something like C# or Common Lisp, and see what the speed-up is. My gut tells me the Rust implementation would use significantly less memory than the CL one, but be only minimally faster, if at all. But my gut has been known to be unreliable in the past.
Re:My negative views on Rust (2021) (2023) by estebank on Thursday October 10, 2024 @02:36PM (#41801870)
When comparing a networked service that wrote to disk (a-la magic wormhole) written in Java and in Rust, after 3 iterations of improvements on the respective implementations the throughput was the same for both, CPU utilization was comparable, but memory usage was orders of magnitude lower for Rust. I think that Java will have difficulty closing the gap until project Valhalla (value types in the JVM) is completed, but even then it'll be difficult to bring the ecosystem along to materialize all its benefits.
Re:My negative views on Rust (2021) (2023) by mwcampbell on Sunday October 13, 2024 @12:38PM (#41829399)
Is that Rust version of Magic Wormhole released?
Re:My negative views on Rust (2021) (2023) by estebank on Monday October 14, 2024 @09:42PM (#41844102)
I saw some time back that a productionalized attempt came out: https://github.com/magic-wormhole/magic-wormhole.rs

The one I mentioned was much more primitive, meant as a demo (you can look at the branches for different approaches): https://github.com/estebank/rusticwormhole

Re:My negative views on Rust (2021) (2023) by danudey on Wednesday October 09, 2024 @05:10PM (#41792659)
This is an old example, but - date/time parsing.

A coworker of mine years ago was trying to parse out some large logfiles and it was running incredibly slowly (because the log file was huge).

Just for fun he profiled the code and found that 90% of the time was spent taking the timestamp ("2019-04-22 15:24:41") into a Python datetime. It was a slow morning, so we went back and forth trying to come up with new methods of optimizing this parsing, including (among other things) creating a dict to map date strings to datetime objects (since there were a lot of repeats).

After some even more profiling, I found that most of the slowdown happened because most of Python's strptime() implementation is written in Python so that it can handle timezones correctly; this prevented them from just calling out to the C library's strptime() implementation.

Since our timestamps didn't have a timezone specified anyway, I wrote my first ever C module[0] for Python, which simply takes two strings (the format and the timestamp) and runs them through strptime and returns a python datetime of the result.

I lost the actual benchmark data before I had a chance to record it somewhere to reproduce, and the Python 3 version in my repo doesn't have as much of a speedup compared to the default Python code, but the initial code that I wrote provided a 47x performance boost to the parsing compared to the built-in Python strptime().

Anyone who had a similar Python script and converted it wholesale to Rust (or C or Golang, probably) would have seen a similarly massive increase in performance.

[0] https://github.com/danudey/pystrptime/

Re:My negative views on Rust (2021) (2023) by jcgrillo on Wednesday October 09, 2024 @05:29PM (#41792868)
One could argue that writing a timestamp as a string which then has to be parsed is silly and instead it should be delta-of-delta encoded and packed into variable width integers, but even then double integrating and constructing a datetime for each one would still be expensive in python, only less so.
Re:My negative views on Rust (2021) (2023) by Aeolos on Wednesday October 09, 2024 @05:06PM (#41792622)
Anecdotal experience: we rewrote an image processing algorithm from numpy+scipy to pure rust and got a 50x speedup in release builds, without even spending any effort optimizing the rust side.

There are further improvements possible around memory allocation and cachelines, but 2 days for 50x improvement was sufficient to not make it worth investing additional effort.

Edit: this was from a team who had _never_ touched Rust before.

Re:My negative views on Rust (2021) (2023) by cyberax on Wednesday October 09, 2024 @04:54PM (#41792505)
> I'm curious what kind of code gets a 45x speedup by going from python to rust

Pretty much any code that is not just tying together external libraries?

Re:My negative views on Rust (2021) (2023) by tuveson on Wednesday October 09, 2024 @05:09PM (#41792648)
If you heavily rely on the Python standard library, then you’re using a lot of Python code that doesn’t call out to C extensions. Peruse the standard library code, if you want to get a sense of it: https://github.com/python/cpython/tree/main/Lib

So you can expect any code that heavily relies on the standard library to be slower than the Rust equivalent.

A purely interpreted language implementation (not JIT’d) like CPython is almost always going to have a 10x-100x slowdown compared to equivalent code in C/C++/Rust/Go or most other compiled/JIT’d languages. So unless your program spends the vast majority of time in C extensions, it will be much slower.

Re:My negative views on Rust (2021) (2023) by Etherlord87 on Wednesday October 09, 2024 @06:08PM (#41793248)
Conway's Game of Life perhaps is a good example: it's a simple program, with a tight loop and cheap calculation in the loop. Python's loops are slow. I wouldn't be surprised if the speedup was much greater than 45x.
Re:My negative views on Rust (2021) (2023) by IshKebab on Wednesday October 09, 2024 @05:08PM (#41792642)
It is basically reading a massive JSON file containing a few thousand logs and then scanning them with a load of regexes.

I was a bit surprised how much faster it was too. Apart from Python being dog slow the only thing I really changed was to use RegexSet which isn't available in Python. I didn't benchmark how much difference that made though; I just used it because it was obviously the right thing to do.

That's kind of the point. If you just do the obvious thing in Rust you get very good performance by default.

It's the same in C++ but then you're writing C++.

Re:My negative views on Rust (2021) (2023) by tialaramex on Thursday October 10, 2024 @02:46AM (#41796233)
The actual regular expression implementation in Rust is going to be fast, but one of the things that caught a reddit poster out only recently was that the Rust regex crate's parser doesn't magically cache, so if you sit in a tight loop making the same regex over and over, it'll do all that work over and over, whereas the Python code might take ten times longer to do it once, then caches it, it doesn't take long for that to end up faster.

Now, if you're going to use RegexSet you're also smart enough to read "For example, it’s a bad idea to compile the same regex repeatedly in a loop" and say "Yeah, makes sense, I will not repeatedly compile the same regex". But some fraction of Python programmers won't read that - and it'll be very slow.

Re:My negative views on Rust (2021) (2023) by burntsushi on Thursday October 10, 2024 @07:37AM (#41797816)
There's plenty of examples like that though. A Python programmer might not know to compile in release mode. They might not use buffering when reading from a file. They might pass around copius copies of Vec<T> instead of &[T]. The list could go on and on.
Re:My negative views on Rust (2021) (2023) by tialaramex on Thursday October 10, 2024 @09:16AM (#41798484)
Sure, and there would probably be some value in a tool which can walk them through the easy stuff before they show a real human code which it turns out just wasn't tested with release optimisations or whatever.

Still, as I understand it CTRE means if you just "use" the same expression over and over in your inner loop in C++ (with CTRE) it doesn't matter, because the regular expression compilation happened in compilation as part of the type system, your expression got turned into machine code once for the same reason Rust will emit machine code for name.contains(char::is_lowercase) once not somehow re-calculate that each time it's reached - so there is no runtime step to repeat.

This is a long way down my "want to have" list, it's below BalancedI8 and the Pattern Types, it's below compile-time for loops, it's below stabilizing Pattern, for an example closer to heart. But it does remind us what's conceivable.

Re:My negative views on Rust (2021) (2023) by burntsushi on Thursday October 10, 2024 @09:38AM (#41798687)
IDK how we jumped to CTRE. Python doesn't do CTRE. It's doing caching. In Rust, you use std::sync::LazyLock for that. I don't get what the problem is to be honest.

I assume by CTRE you're referring to the CTRE C++ project. That's a totally different can of worms and comes with lots of trade-offs. I wish it were easy to add CTRE to rebar, then I could probably add a lot more color to the trade-offs involved, at least with that specific implementation (but maybe not to "compile time regex" in general).

Re:My negative views on Rust (2021) (2023) by tialaramex on Thursday October 10, 2024 @12:31PM (#41800547)
I jumped to CTRE because it's another way that you can get the better results. The programmer need have no idea why this works, just like with caches.

I agree that there are trade-offs, but nevertheless compile time regex compilation is on my want list, even if a long way down it. I would take compile time arithmetic compilation† much sooner, but since that's an unsolved problem I don't get that choice.

† What I mean here is, you type in the real arithmetic you want, the compiler analyses what you wrote and it spits out an approximation in machine code which delivers an accuracy and performance trade off you're OK with, without you needing to be an expert in IEEE floating point and how your target CPU works. Herbie https://herbie.uwplse.org/ but as part of the compiler.

Re:My negative views on Rust (2021) (2023) by sfink on Friday October 11, 2024 @06:48PM (#41814633)
My "I'm gonna learn Rust!" initial project was porting a callgraph traversal tool from Python to Rust. For loading in my input file, the speedup was very disappointing: 1x. (As in, no speedup at all.)

Then I learned about the `--release` flag and it instantly became a 40x speedup. So that was nice.

Waiting 30s vs <1s puts it well within "anything requiring remotely decent speeds". But it was really about parsing a custom data format, nothing fancy. I haven't done comparison timings of the graph traversals, but everything is basically instantaneous in the Rust version and not in the Python.