Re:Is Rust Stack-Efficient Yet?
by CapmCrackaWaka on Thursday November 17, 2022 @08:54AM
(#33638882)
If you don't mind me asking - how do you witness these low level memory allocations? Specific program, plugin to vs code?
[ Parent
| on HN ]
Re:Is Rust Stack-Efficient Yet?
by spacechild1 on Thursday November 17, 2022 @09:15AM
(#33639127)
You look at the generated assembly.
The simplest way to make quick experiments for me is with https://godbolt.org/ .
For my particular example: https://godbolt.org/z/8GvYzYj5h
You can see we're trying to put a 1kB object on heap, but the compiler generates two `memcpy` calls - first to copy it on stack to build the wrapper struct, second to actually copy the entire struct onto allocated memory.
In "real programs", you just need to look at the program's assembly. Or even more generally, I originally noticed this when observing the unusually high amount of time spent in some functions when profiling.
Other than Godbolt Rust also has cargo-show-asm[1] that directly shows the actual assembly.