Hacker News new | ask | show | jobs
by wrs 780 days ago
I’m a Rust newbie, wondering how f32::clone could show up in a profile. Wouldn’t that be an inline no-op under any kind of optimization? I mean, cloning a float is, at worst, a MOV instruction, no?
2 comments

Profiles aren’t always entirely accurate. That’s kinda fine, since (IMO) they’re mainly useful for pointing you in the correct direction.

Once you’ve found a small enough chunk of logic that’s worth optimizing, I’d recommend relying more on benchmarks and disassembly.

Floats aren't stored in the same kinds of registers.
How would that make any difference to what is being discussed?
fmov is an instruction -> not a no-op
The article is doing profiling on x86-64. There is no FMOV. Floating point on x86-64 is done in the SSE or AVX (xmm, ymm) registers loaded with MOVD/Q which has basically the same addressing modes as any of the usual GPR loads/moves. In any case in optimized code, something like a scalar clone is inlined and would not be a consistent accountable and localizable operation (and may even be optimized away).
My point is, whatever it is, it can't possibly be a function call, so how would it ever legitimately show in a profile? I like pcwalton's theory.

The practical implication is that trying to optimize "calls to f32::clone" because they're in a profile is a wild goose chase -- unless you have debug anti-optimization turned on, there shouldn't be any calls to f32::clone.