Live data from Hacker News

Rust is for Professionals

gregoryszorc.com

141–150 of 157 posts

Re: Rust is for Professionals

#141

Earlier quoted context omitted.

Cloning means runtime inefficiency, but the cost is so pathetically small compared to the amount of code we run in Python and Java with their larger footprints. Yes. Clone more.

This is one of the psychological traps I've experienced writing Rust: in Python or Java you can't hope to make things more efficient at a certain point. You couldn't get clever with string re-use if you tried, etc. So you're content to just move forward and be practical. Whereas in Rust you know that it's probably possible to use a &str there instead of a String. If you just bang on it a little longer, you can make i…

> You have to consciously talk yourself out of that if you want to be productive.

That's 100% correct but there's one problem: how do you write down your future improvement opportunities?

Skip 2 optimizations here, 3 optimizations there and after 30 PRs you can easily have notes spanning 100 bullet points on what to optimize one day in the future Soon™.

I am still not at what I'd call an expert level in Rust -- and the skill ceiling is quite high -- so maybe with time I'd start to automatically spot these optimization opportunities?

But before I am at that level I'd prefer to either keep hugely long notes or, ideally, have a tool recommend optimizations to me.

Re: Rust is for Professionals

#142
post #80

Rust sounds like a pretty promising language. Considering in the future everything will run in garbage collected VMs written in C++ anyway ;)

Nope. In the future it's going to be JavaScript engines all the way down.

How can a js engine self host?

Re: Rust is for Professionals

#143
post #12

Here I am on day three of an attempt to modify a rust program with logic that would have taken about twenty minutes to implement in C# or Java. It has to do with operations on strings (use a regex to find a string in some text, escape all the regex-reserved characters in that string, then use the string as a regex to find other occurrences of itself in the text) so I get that I'm really thrown into the borrow-checker…

This is my experience with the language. It's a good language - but it's a tool at the end of the day. One with edges and trade offs like any other. I can't help but think the people like the author only feel "giddy" because its been hyped up on this website.

Re: Rust is for Professionals

#144
post #111

Earlier quoted context omitted.

The error output for your code is error[E0382]: use of moved value: `suffix` --> cli/src/test.rs:416:48 | 406 | let suffix = FIRST_HEADER_REGEX | ------ move occurs because `suffix` has type `std::option::Option `, which does not implement the `Copy` trait ... 414 | .map(|s| String::from(r"^===+") + &s + r"\r?\n([^=]*)\r?\n===+" + &s + r"\r?\n"); | ---------------------------------------------------------------------…

The latter change introduces an unnecessary clone(). The correct approach is to instead introduce a variable so that headerRegex can keep being a reference to either that variable or to HEADER_REGEX.

Can you expand on how this stops a clone from happening?

Re: Rust is for Professionals

#146
post #111

Earlier quoted context omitted.

The latter change introduces an unnecessary clone(). The correct approach is to instead introduce a variable so that headerRegex can keep being a reference to either that variable or to HEADER_REGEX.

Can you expand on how this stops a clone from happening?

If you don't call clone() then a clone doesn't happen...

Re: Rust is for Professionals

#147
post #146

Earlier quoted context omitted.

Can you expand on how this stops a clone from happening?

If you don't call clone() then a clone doesn't happen...

Ah, I didn't see the extra clone. I thought it was something to do with that additional variable you defined. I guess you need to do that or else you have to do a clone.

Re: Rust is for Professionals

#148

Earlier quoted context omitted.

This is one of the psychological traps I've experienced writing Rust: in Python or Java you can't hope to make things more efficient at a certain point. You couldn't get clever with string re-use if you tried, etc. So you're content to just move forward and be practical. Whereas in Rust you know that it's probably possible to use a &str there instead of a String. If you just bang on it a little longer, you can make i…

> You have to consciously talk yourself out of that if you want to be productive. That's 100% correct but there's one problem: how do you write down your future improvement opportunities? Skip 2 optimizations here, 3 optimizations there and after 30 PRs you can easily have notes spanning 100 bullet points on what to optimize one day in the future Soon™. I am still not at what I'd call an expert level in Rust -- and t…

The simplest tool is to just grep for various constructs that copy or allocate. Clippy, the Rust linter, will find some of these (as well as other issues, some of which tend to cause performance problems).

The better tool is to profile the code, then optimize hotspots. There's a Rust Performance Book with a list of profilers known to work with Rust programs[1]. Rustc does support Profile Guided Optimization[2] which is often pretty good at speeding up the output even without any code changes.

[1] https://nnethercote.github.io/perf-book/profiling.html [2] https://doc.rust-lang.org/rustc/profile-guided-optimization....

Re: Rust is for Professionals

#149

Earlier quoted context omitted.

> You have to consciously talk yourself out of that if you want to be productive. That's 100% correct but there's one problem: how do you write down your future improvement opportunities? Skip 2 optimizations here, 3 optimizations there and after 30 PRs you can easily have notes spanning 100 bullet points on what to optimize one day in the future Soon™. I am still not at what I'd call an expert level in Rust -- and t…

The simplest tool is to just grep for various constructs that copy or allocate. Clippy, the Rust linter, will find some of these (as well as other issues, some of which tend to cause performance problems). The better tool is to profile the code, then optimize hotspots. There's a Rust Performance Book with a list of profilers known to work with Rust programs[1]. Rustc does support Profile Guided Optimization[2] which…

Helpful links, thank you!

> The simplest tool is to just grep for various constructs that copy or allocate.

Do you happen to have a curated list somewhere?

Re: Rust is for Professionals

#150

Earlier quoted context omitted.

The simplest tool is to just grep for various constructs that copy or allocate. Clippy, the Rust linter, will find some of these (as well as other issues, some of which tend to cause performance problems). The better tool is to profile the code, then optimize hotspots. There's a Rust Performance Book with a list of profilers known to work with Rust programs[1]. Rustc does support Profile Guided Optimization[2] which…

Helpful links, thank you! > The simplest tool is to just grep for various constructs that copy or allocate. Do you happen to have a curated list somewhere?

For allocations (more expensive in many cases) the Rust container cheat sheet[1] is helpful. Box, Vec, Rc, Arc, and Mutex are the standard types which allocate.

Not sure of a list for things that copy their data. The Clone trait is the obvious one, and it requires calling clone() to make the copy. EG `val.clone()`. So searching for `.clone()` will get you those. But other things like to_string are expensive, and From/Into are sometimes expensive.

[1] https://docs.google.com/presentation/d/1q-c7UAyrUlM-eZyTo1pd...

Post reply on HN