Are small structs stored in registers when inlining?
Say I have a simple struct to represent an image:
struct Image {
width: u32,
height: u32,
data: Vec<f32>,
}
It has a method fn sample(&self, x: f32, y: f32) -> f32, which linearly interpolates the image to produce a pixel value at the exact location. The method is #[inline].
This method is usually called repeatedly in small ("hot"?) loops, meaning it should be as fast as possible. Because it reads the width and data variables on each call, it would make sense to store them in CPU registers, and modify the machine code of the sample method to read them from registers when it is inlined. Does this optimisation happen? Or will they be read from the in-memory struct each time, requiring a whole memory access?
This seems like an obvious optimisation, but I don't know how to correctly search for this information.
These kind of hot loops you'd hand code in C, but it feels like Rust inlining optimisation should be able to do that automatically? Thanks to the mutability/aliasing rules...