On Mon, Oct 14, 2019 at 9:05 AM Gerald Squelart <gsquel...@mozilla.com> wrote:
> I'm in the middle of watching Chandler Carruth's CppCon talk "There Are No 
> Zero-Cost Abstractions" and there's this interesting insight:
> https://youtu.be/rHIkrotSwcc?t=1041
> The spoiler is already in the title (sorry!), which is that passing 
> std::unique_ptr by value is more expensive than passing it by rvalue 
> reference, even with no exceptions!
> I wrote the same example using our own mozilla::UniquePtr, and got the same 
> result: https://godbolt.org/z/-FVMcV (by-value on the left, by-rref on the 
> right.)
> So I certainly need to recalibrate my gutfeelometer.

The discussion in the talk about what is needed to fix this strongly
suggested (without uttering "Rust") that Rust might be getting this
right. With panic=abort, Rust gets this right (
https://rust.godbolt.org/z/SZQaAS ) which really makes one appreciate
both Rust-style move semantics and the explicitly not-committal ABI.

(I had to put a side-effectful println! in bar to make sure a call to
bar is generated, since #[inline(never)] isn't enough to prevent the
compiler from eliding calls to functions it can see do nothing.)

Henri Sivonen
dev-platform mailing list

Reply via email to