Godbolt Link
As you can see in the asm output, even set opt-level = 3, if we don't add Copy to structs with all fields Copy derived, in clone() it generates more mov and large struct can't trigger memcpy, I suggest to add Copy to them to alleviate binary size bloated and performance problem.
List of structs that could add Copy (Simple search may miss):
I didn't realize this happens. Very good catch! We'll definitely look into this. It's a shame rustc optimizes non-Copy types so much worse, though, even when they're otherwise identical.
Godbolt Link As you can see in the asm output, even set
opt-level = 3
, if we don't addCopy
to structs with all fieldsCopy
derived, inclone()
it generates moremov
and large struct can't triggermemcpy
, I suggest to addCopy
to them to alleviate binary size bloated and performance problem. List of structs that could addCopy
(Simple search may miss):