ABI: Ownership transfer through pointer involves unnecessary copies #86711
Labels
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
Let's say we have a reasonably large struct that doesn't get passed through registers:
Then we have some method on it that requires ownership transfer:
And then we have some sort of function that just passes ownership through to that method:
In C you would expect a "copy" of the struct to get passed into the function, as we pass the struct by value. And that's exactly what Rust does here as well. It copies the entire struct onto the stack and then passes a pointer to the copy into the function:
However Rust has a unique notion of ownership, where we know that
color
can't be used anymore after calling the method. So no actual copy should ever be necessary for a non-Copy
type. Though technically even on aCopy
type no such additional copy should be necessary if it's the last use.https://rust.godbolt.org/z/135z7aK3K
The text was updated successfully, but these errors were encountered: