Do PDB Files Affect Performance?
After a detour into Historical Debugging, it’s time to come back to return to answering questions about PDB files. Here’s a question from Justin:
Thanks for the great post once again. I was looking forward to your debugging virtual training, but unfortunately it was cancelled.
The company I work for is pushing pack against building release mode
binaries with debug information generated, one of the reasons I signed
up for the class :). They are afraid performance will be affected.
My question is what are the best command line arguments for
generating symbols in release mode? Also is there somewhere I can
reference to show that there should be no performance hits.
I’m sorry about the canceled class, but the good news is that Mastering .NET Debugging was rescheduled to July 14-15.
The executive summary answer: no, generating PDB files will have no
impact on performance whatsoever. As for references that I can point you
too, I haven’t found any on the web that answer the exact question so
let me take both .NET and native development in turn.
Recently, the always-readable Eric Lippert wrote a great post What Does the Optimize Switch Do?
where he discusses the optimizations done by the compiler and Just in
Time (JIT) compiler. (Basically, you can sum it up as the JITter does
all the real optimization work.) There’s a bit of confusion on the C#
and VB.NET compiler switches around as there are four different /debug
switches, /debug, /debug+, /debug:full, and /debug:pdb-only. I
contributed to that confusion because I thought /debug:pdb-only did
something different that was better for release builds than the other
three /debug switches.
All four switches all do the same thing in that they cause a PDB file
to be generated but why are there four switches to do the same thing?
Do Microsoft developers really love parsing slightly different command
line options? The real reason: history. Back in .NET 1.0 there were
differences, but in .NET 2.0 there isn’t. It looks like .NET 4.0 will
follow the same pattern. After double-checking with the CLR Debugging
Team, there is no difference at all.
What controls whether the JITter does a debug build is the /optimize switch. Building with /optimize- will add an attribute, DebuggableAttribute, in the assembly and setting the DebuggingMode
parameter to DisableOptimizations. It doesn’t take a Rhodes Scholar to
figure out that DisableOptimizations does exactly what it says.
The bottom line is that you want to build your release builds with
/optimize+ and any of the /debug switches so you can debug with source
code. Read the Visual Studio documentation to see how where to set those switches in the different types of projects.
It’s easy to prove these are the optimal switches. Taking my Paraffin program, I compiled one build with /optimize+ and /debug, and another with just /optimize+.
which is the same as /debug+ and /debug, and the other with /optimize+ /debug:pdbonly to show the differences, which is the root of how we got it wrong. After compiling, I used ILDASM with the following command line to get the raw information from the binaries
ILDASM /out=Paraffin.IL Paraffin.exe
Using a diff tool you’ll see that the IL itself is identical between both builds. The main difference will be in the DebuggableAttribute declaration for the assembly. When built /optimize+ and a /debug switch, a DebuggingMode.IgnoreSequencePoints is passed to the DebuggableAttribute to tell the JIT compiler that it doesn’t need to load the PDB file in order to correctly JIT the IL. A value of DebuggingMode.Default is also OR’d in, but that value is ignored.
Like .NET, building PDB files has nothing to do with optimizations so have zero impact on the performance of an application. If you have a manager who in Justin’s words is “afraid performance will be affected” here’s what I tell them. (Sadly, I’ve run into a few more managers who say that than I care to count).
That might be true on other operating systems, but not Windows. If you think they do, then why does Microsoft build every single product they ship with PDB files turned on for both debug and release builds? They wrote the compiler, they wrote the linker, and they wrote the operating system so they know exactly what the effects are. Microsoft has more people focused on performance than any other software company in the world. If there were any performance impact at all, they wouldn’t do it. Period. Performance isn’t the only thing at Microsoft, it’s everything.
Where .NET is pretty simple as there’s really only two switches, the appropriate optimization switches are dependent on many individual application factors. What I can tell you is what the switches you need to set to generate PDB files correctly in release builds.
For CL.EXE, the compiler, you need to add /Zi to have it put debugging symbols into the .OBJ file. For LINK.EXE, the linker, you need to specify three options. The first is /DEBUG, that tells the linker to generate a PDB file. However, that switch also tells the linker that this is a debug build. That’s not so good because that will affect the performance of your binary. Basically what happens when you use /DEBUG is the linker links faster because it no longer looks for individual references. If you use one function from a OBJ the linker throws the whole OBJ into the output binary so you now have a bunch of dead functions.
To tell the linker you want only the referenced functions, you need to add /OPT:REF as the second switch. The third switch is /OPT:ICF, which enabled COMDAT folding. There’s a term you don’t hear every day. Basically what this means is that when generating the binary, the linker will look for functions that have identical code and only generate one function but make multiple symbols point to the one function.
If you want to test the difference yourself on a native binary to see what affects generating PDB files will have, it’s nearly as easy as a .NET binary. Visual Studio comes with a nice little program, DUMPBIN, which can tell you more than you ever wanted to know about a Portable Executable file. Run it with /DISASM switch to get the disassembly of a binary.
Please keep those PDB related questions coming. Of course, if you have any other questions, I’ll be happy to take a crack at those also. Gee, I better draw the line: no investment or relationship questions. <grin>
Do PDB Files Affect Performance?的更多相关文章
- PDB Files: What Every Developer Must Know
Reference: http://www.wintellect.com/blogs/jrobbins/pdb-files-what-every-developer-must-know Most d ...
- PDB文件:每个开发人员都必须知道的 PDB Files
PDB文件:每个开发人员都必须知道的 PDB Files: What Every Developer Must Knowhttp://www.wintellect.com/CS/blogs/jro ...
- PDB files out of the debugger
我想我不需要强调在调试时拥有有效的PDB文件有多重要.通常,PDB文件是由调试器静默加载的,并且您很高兴在modules窗口中看到解析的所有符号.不幸的是,您还可能遇到调试器找不到匹配符号的情况.其原 ...
- Why is Visual Studio 2015 not able to find or open PDB files?
first change parameters, Tools->Options->Debugging->Symbols->Microsoft Symbol Server, ye ...
- pdb文件 PDB文件:每个开发人员都必须知道的 .NET PDB文件到底是什么?
pdb文件包含了编译后程序指向源代码的位置信息,用于调试的时候定位到源代码,主要是用来方便调试的. 在程序发布为release模式时,建议将 pdb文件删除, 同时,对外发布的时候,也把 pdb删除, ...
- 【C# 调试】.net中的 .pdb文件是什么,有什么用
mscn:在 Visual Studio 调试器(C#)中指定符号 (.pdb) 和源文件 PDB全称Program Database,程序数据库 ( .pdb) 文件(也称为符号文件)将项目源代码中 ...
- 网站发布IIS后堆栈追踪无法获取出错的行号
一.问题起因 系统发布上线后,有时会发生错误,那么错误的记录就很重要,它对于错误的排查和问题的发现有着重要的作用,通常我们采取的方式为Log日志文件记录和数据库错误记录.文本不会讨论错误记录的方式以及 ...
- PostgreSQL Hardware Performance Tuning
Bruce Momjian POSTGRESQL is an object-relational database developed on the Internet by a group of de ...
- Chapter 6 — Improving ASP.NET Performance
https://msdn.microsoft.com/en-us/library/ff647787.aspx Retired Content This content is outdated and ...
随机推荐
- BehaviorTree.CPP行为树BT的装饰器节点(五)
Decorators 装饰器是只能有一个子项的节点. 由装饰者来决定是否,何时以及对子节点进行tick. InverterNode tick子节点一次,如果子节点失败则返回SUCCESS,如果孩子成功 ...
- 『学了就忘』Linux文件系统管理 — 59、使用fdisk命令进行手工分区
目录 1.手工分区前提 (1)要有一块新的硬盘 (2)在虚拟机中添加一块新硬盘 2.手工分区 (1)查看Linux系统所有硬盘及分区 (2)手工分区:详细步骤 (3)保存手工分区 3.硬盘格式化 4. ...
- 洛谷 P5071 - [Ynoi2015] 此时此刻的光辉(莫队)
洛谷题面传送门 一道其实算得上常规的题,写这篇题解是为了总结一些数论中轻微(?)优化复杂度的技巧. 首先感性理解可以发现该问题强于区间数颜色问题,无法用常用的 log 数据结构维护,因此考虑分块/莫队 ...
- 洛谷 P3647 [APIO2014]连珠线(换根 dp)
题面传送门 题意: 桌子上有 \(1\) 个珠子,你要进行 \(n-1\) 次操作,每次操作有以下两种类型: 拿出一个新珠子,并选择一个桌子上的珠子,在它们之间连一条红线 选择两个由红线相连的珠子 \ ...
- 一类利用队列优化的DP
I.导入: 这是一个\(O(n^2)\)的状态和转移方程: \[f(i,j)=\left\{ \begin{aligned} f(i-1,j-1)+k \ (1\leq j)\\ \max_{k \i ...
- BJ2 斜率限制器
BJ2 斜率限制器 本文介绍斜率限制器取自于 Anastasiou 与 Chan (1997)[1]研究,其所利用的斜率限制器也是 Barth 与 Jespersen 限制器的一种修正形式,并且包含一 ...
- 【蛋白质基因组】Proteogenomics方法介绍及分析思路
概念 利用蛋白质组学数据,结合基因组数据(DNA).转录组数据(RNA)来研究基因组注释问题,被称为蛋白质基因组学."蛋白质基因组学"一词由Jaffe 等于2004 年首次提出,作 ...
- jQuery添加html绑定事件
jQuery添加html绑定事件 $("#xxx").on("click",".dev",function(){ });
- 半主机模式和_MICROLIB 库
半主机是这么一种机制,它使得在ARM目标上跑的代码,如果主机电脑运行了调试器,那么该代码可以使用该主机电脑的输入输出设备. 这点非常重要,因为开发初期,可能开发者根本不知道该 ARM 器件上有什么 ...
- 50. Plus One-Leetcode
Plus One My Submissions QuestionEditorial Solution Total Accepted: 98403 Total Submissions: 292594 D ...