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.)

  • \$\begingroup\$ Can you show us your compiler output? As I understand from consulting Rust-savvy colleagues, 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 like Finished foo [unoptimized + debuginfo] or Finished foo [optimized + debuginfo]. \$\endgroup\$
    – DMGregory
    Commented Mar 18, 2023 at 21:21
  • \$\begingroup\$ C Snover nailed it in his reply, and this comment helped me confirm that was what was going on. Thanks, DMGregory! \$\endgroup\$
    – sclamons
    Commented Mar 18, 2023 at 21:56

1 Answer 1


Per the Flamegraph README, it runs using the release profile by default:

# defaults to profiling cargo run --release
cargo flamegraph

So you must also run using the release profile, by running cargo run --release, to see the same performance.

  • \$\begingroup\$ That was it! Flamegraph was definitely setting the --release flag, which I, a n00b, did not know about. Thank you! \$\endgroup\$
    – sclamons
    Commented Mar 18, 2023 at 21:55
  • \$\begingroup\$ If this solved your problem, @sclamons, remember to click the checkmark icon on the left to mark the answer as "Accepted". \$\endgroup\$
    – DMGregory
    Commented Mar 18, 2023 at 23:18
  • \$\begingroup\$ Ah, thanks for the reminder! \$\endgroup\$
    – sclamons
    Commented Mar 20, 2023 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .