Will debug symbols affect the performance in Rust?
Asked Answered
R

1

-1

I'm running Rust utilities that compiled with debug symbols.

cargo build 
# without the "--release" flag   

These are really slow compared to the same utilities written in C.

Is it possible that the debug symbols affected the performance?

Replenish answered 20/7, 2020 at 15:11 Comment(3)
It looks like your question might be answered by the answers of How do debug symbols affect performance of a Linux executable compiled by GCC?. If not, please edit your question to explain the differences. Otherwise, we can mark this question as already answered.Roast
When you build with "cargo build" without "--release", you get a debug build. The difference with a release build is not just debug symbols. A debug build is not optimized and therefore will run a lot a slower than a release build.Exigible
Does this answer your question? How do debug symbols affect performance of a Linux executable compiled by GCC?Yt
R
5

Answering your question

Compiling with debug symbols will usually make your binary larger on Linux and UNIX-like platforms. This may mean that you need to load more data from disk, which can affect performance. There shouldn't really be any runtime difference.

You can split the debugging information into separate files to avoid increasing the size of your binaries. Windows does this by default with PDB files and macOS does this by default with dSYM files.

See also:

Addressing your problem

If you don't compile with --release, your code will be slower. Compile with --release if you are judging performance.

Switching between debug mode and release mode can change more than just debug symbols. The level of optimization is one example, overflow checking is another. To my knowledge, there's no complete list of what changes, other than reviewing the Cargo and Rust source code.

See also:

Roast answered 20/7, 2020 at 15:17 Comment(2)
It would be interesting to add that the difference between a debug and a release build is far from just the addition of the debug symbols. Most optimizations aren't performed with a debug build (because they would affect how usable that build is for actual debugging).Shandeigh
You can find a complete (?) list of the differences between profiles here: doc.rust-lang.org/cargo/reference/profiles.html. Other changes include disabling debug assertions and disabling incremental compilation.Gui

© 2022 - 2024 — McMap. All rights reserved.