I'm making a simple SDL2-based Rust game, on an OSX laptop. Graphics mostly involves drawing lots of colored squares to the screen. Performance is really slow for what I'm doing, so I decided to profile with Flamegraph. The weird thing is, when I run with flamegraph, performance improves dramatically, going from ~20-50ms/frame to more like 5-10ms/frame. What could possibly be causing this (and how can I take advantage of it)?
Here's the command I use to run the program normally:
sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo run
Here's the command I use to run the program with flamegraph:
sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph
(Flamegraph requires some permissions to run, so I run them both with sudo for maximum comparability.)
CARGO_PROFILE_RELEASE_DEBUG
controls only whether to emit debug info for a release build, not whether to compile as debug vs release, so it's possible Flamegraph is changing your build output. Look for a line that says something likeFinished foo [unoptimized + debuginfo]
orFinished foo [optimized + debuginfo]
. \$\endgroup\$