Honest question - does this mean Rust isn't ready for production yet?
No. TFA points out there isn’t a gigantic performance sink or anything, just an infelicity in the code they’re generating. >> Does this mean Rust is slower than C++? > No. You can always write your Rust code carefully to avoid copies. Besides, all of this only comes out to a small percentage of the total instruction count. That being said, it's something we should fix, and which I'm working on.
Is Rust stack-efficient yet?
71–80 of 111 posts
Re: Is Rust stack-efficient yet?
#72Honest question - does this mean Rust isn't ready for production yet?
Re: Is Rust stack-efficient yet?
#73Re: Is Rust stack-efficient yet?
#74This affects the way you write code, too. I was writing something in Rust and I wanted to create a new boxed object. Box::new(...) Boom! Program crashes. The object I’m putting in the heap is too large for the stack. Rustc does this by instantiating the object on the stack, and then copying it to the box. I don’t really want to fuss with nightly or stuff like Box::new_uninit just to deal with this. C++ has both regul…
Maybe in another ten years the language will mature.
Re: Is Rust stack-efficient yet?
#75This affects the way you write code, too. I was writing something in Rust and I wanted to create a new boxed object. Box::new(...) Boom! Program crashes. The object I’m putting in the heap is too large for the stack. Rustc does this by instantiating the object on the stack, and then copying it to the box. I don’t really want to fuss with nightly or stuff like Box::new_uninit just to deal with this. C++ has both regul…
It seems crazy to me that something as trivial as allocating heap space needs rust nightly and unsafe. And people want to rewrite the world in Rust. Maybe in another ten years the language will mature.
It seems crazy to you because your spectacular misdescription of the problem is simply incorrect.
Re: Is Rust stack-efficient yet?
#76Earlier quoted context omitted.
No. TFA points out there isn’t a gigantic performance sink or anything, just an infelicity in the code they’re generating. >> Does this mean Rust is slower than C++? > No. You can always write your Rust code carefully to avoid copies. Besides, all of this only comes out to a small percentage of the total instruction count. That being said, it's something we should fix, and which I'm working on.
As pointed out elsewhere in this comment tree, things living on the stack when they needn't can mean they don't fit and thus the program doesn't work, so the optimisation can matter for that reason, and this is a particular reason to worry about it for larger objects where the optimiser is more likely not to see what's going on.
People are acting like this graph they saw for the first time today means that Rust is running at sub-Ruby speeds, when even with these excess copies we already know, and have known for years how rust programs have been performing in real life.
That there is room for improvement here does not mean that the status quo was not already excellent.
Re: Is Rust stack-efficient yet?
#77But why are these operations slow in Rust?
Re: Is Rust stack-efficient yet?
#78We need &out and &in, so we can safely write this stuff by hand. Then we can worry about the compiler automatically optimizing to use &out behind the scenes (using ABI flexibility). Trying to skip that first step, so the compiler just does unverified shit behind the scenes, I think will just end up with inflexibility and disappointment. Be the tortoise not the hare.
Easier said than done. You can already have: unsafe fn new_in_place(out: &mut MaybeUninit ) But you require unsafe code both to implement it (to project MaybeUninit) and to call it. For it to be safe to call the type system would have to encode the invariant that &out is initialised after the call. It becomes even more complicated if the operation can fail.
If one doesn't want to deal with imperative programming in all its glory, go write Haskell or something. (I do that too.)
Re: Is Rust stack-efficient yet?
#79I would love to see this for C#. Avoiding heap allocations was something I had to tackle as part of a simulation software. C# has a handful of GC generations, and GC gen1 is very fast, but it's still faster to pool things ahead of time.
Re: Is Rust stack-efficient yet?
#80This affects the way you write code, too. I was writing something in Rust and I wanted to create a new boxed object. Box::new(...) Boom! Program crashes. The object I’m putting in the heap is too large for the stack. Rustc does this by instantiating the object on the stack, and then copying it to the box. I don’t really want to fuss with nightly or stuff like Box::new_uninit just to deal with this. C++ has both regul…
If constructing the object doesn't have side effects, however, then we should be able to hoist the allocation at the optimizer level.