I jokingly suggested to a friend adding fast { .. } which somehow makes the code in the block “faster”. He actually thought something like that could be useful, with the semantics of “always apply optimizations, even if in debug mode”.
I think some mechanism to do this could be useful… like an attribute #[hot] that tells the compiler to always run all possible optimizations on the body of a function, as if in release mode. The suggested use case my friend wanted was for a tight graphics loop in a game engine; apparently, runtime checks in debug mode stacked up to make the compiled executable too slow to effectively test. So, my friend would replace
loop {
unsafe {
// my graphics magic here
}
}
with
loop {
unsafe {
#[hot]
unsafe fn graphics_magic(..) { .. }
graphics_magic(..);
}
}
I have no idea how optimizations work at the MIR level though, so something like this might be difficult to do, or maybe even undesireable!