Should small Rust structs be passed by-copy or by-borrow?
forrestthewoods.com
Should small Rust structs be passed by-copy or by-borrow?
1–10 of 115 posts
Re: Should small Rust structs be passed by-copy or by-borrow?
#2Anyway good article.
Re: Should small Rust structs be passed by-copy or by-borrow?
#3Re: Should small Rust structs be passed by-copy or by-borrow?
#4Re: Should small Rust structs be passed by-copy or by-borrow?
#5Re: Should small Rust structs be passed by-copy or by-borrow?
#6For the difference between rust and C++ I'd say is caused by the difference between rustc+llvm and msvc++ compilers. Compiling C++ under clang should give more comparable results
Re: Should small Rust structs be passed by-copy or by-borrow?
#7Thanks for sharing. As a Rust learner, I still don't know how to place the cursor between performance with borrowing and ergonomic with copying. Most of the time, I just copy/clone and I tell myself that the performance does not matter that much because it will be fast enough for my purpose anyway.
It probably will be.
I've been using Rust in production for a while now, and our bottlenecks are never Rust's performance. Something else is the bottleneck way before we approach anything close to Rust's peak throughput. This is especially true if you're doing anything that touches networking or interacts with other services.
Re: Should small Rust structs be passed by-copy or by-borrow?
#8If you were to discuss the headline issue, I guess you could delve deep into calling conventions, register pressure, various instruction set extensions that compilers can abuse to carry the data.. or you take the compiler optimizations as a hint that concerning yourself with this is mostly pointless, as long as you don't start passing huge structures by-copy.
Re: Should small Rust structs be passed by-copy or by-borrow?
#9For the difference between rust and C++ I'd say is caused by the difference between rustc+llvm and msvc++ compilers. Compiling C++ under clang should give more comparable results
Re: Should small Rust structs be passed by-copy or by-borrow?
#10In the below example Rust switches to using a pointer when you might think it's doing pass by copy/move. This works because in Rust the moved value can never be referenced after calling the function, so the compiler can just pass a pointer and clean up the value after the function has returned.
https://www.reddit.com/r/rust/comments/3g30fw/how_efficient_...