Unexpected outcome with higher optimisation levels
⚓ Rust 📅 2025-12-04 👤 surdeus 👁️ 2Hello.. I noticed something very weird while trying out some rust profiles today. I have this profile.
[profile.release-max]
inherits = "release"
lto = "fat"
codegen-units = 1
panic = "abort"
opt-level = 3
This seems to be completely removing my prometheus metrics and tracing::trace! logs in the following block of code, when compiled for linux-arm64 ..
let updated = self.subs.clone();
tracing::trace!(?updated, "sending updates to writer");
self.metric_active_subs.observe(updated.len() as f64);
self.send_cmd(Cmd::Modes(updated)).await?;
self.ctrl.apply(self.id, to_sub, to_unsub, to_replay).await;
It looks like the tracing::trace! line and the self.metric_active_subs line are getting removed completely (no metrics in my endpoint and this log doesn't come even with trace level enabled)..
Is this expected? observe() has side-effects, so compiler shouldn't end up removing that?..
Interestingly, same profile doesn't remove these on my MacOS M2 arm64.
Note: Tracing is definitely not globally disabled in release builds because I can see other trace logs from different parts of the same module too.
1 post - 1 participant
🏷️ Rust_feed