我正在运行使用调试符号编译的 Rust 实用程序.
I'm running Rust utilities that compiled with debug symbols.
cargo build # without the "--release" flag与用 C 编写的相同实用程序相比,这些真的很慢.
These are really slow compared to the same utilities written in C.
调试符号是否有可能影响性能?
Is it possible that the debug symbols affected the performance?
推荐答案回答你的问题
使用调试符号进行编译通常会使您的二进制文件在 Linux 和类 UNIX 平台上变大.这可能意味着您需要从磁盘加载更多数据,这会影响性能.应该没有任何运行时差异.
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.
您可以将调试信息拆分为单独的文件,以避免增加二进制文件的大小.Windows 默认使用 PDB 文件执行此操作,macOS 默认使用 dSYM 文件执行此操作.
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.
另见:
- 调试符号如何影响 GCC 编译的 Linux 可执行文件的性能?
如果你不使用 --release 编译,你的代码会变慢.如果要判断性能,请使用 --release 编译.
If you don't compile with --release, your code will be slower. Compile with --release if you are judging performance.
在调试模式和发布模式之间切换可以改变的不仅仅是调试符号.优化级别是一个例子,溢出检查是另一个例子.据我所知,除了查看 Cargo 和 Rust 源代码之外,没有完整的更改列表.
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.
另见:
- 使用cargo时如何获取带有调试信息的发布版本?
- 如何在启用溢出检查的情况下编译和运行优化的 Rust 程序
更多推荐
调试符号会影响 Rust 的性能吗?
发布评论