views:

117

answers:

2

If a .pdb (program debug) file is included with a .dll then line numbers appear in the stack trace of any exception thrown. Does this affect the performance of the application?


This question is not about release vs. debug, i.e. optimisations. It is about the performance implications of having .pdb files. Are the .pdb files read every time an exception is thrown? Is the information cached in some way when the assemblies are loaded? Or is it cached the first time a relevant exception is thrown? How much difference does it make?

+5  A: 

Not normally. PDBs and optimizations are orthogonal. One can be enabled regardless of the value of the other option. However, it might reduce performance if you want to actually use the information contained in PDB, like when you are accessing the StackTrace of an exception and it needs to get line numbers from PDB or when you call new StackTrace(true).

By the way, Eric Lippert has a related blog entry about compiler optimizations.

Mehrdad Afshari
What do you mean 'not normally'? When will it have an effect? Also, I fail to see how the fact that one can both have PDBs and enable optimizations answers the question.
Matt Howells
I mentioned the specific case I think it might affect performance: when you need to look up information from it as you build a stack trace. The compiler can generate identical IL whether or not a PDB is generated and JIT optimizer also doesn't care whether PDB is there or not to enable its optimizations. As a consequence, when the generated machine code is identical, there's no reason that existence of a PDB would reduce performance.
Mehrdad Afshari
+3  A: 

John Robbins wrote about this in his article Do PDB Files Affect Performance?. The simple answer is no (if you compile your release build with both the /optimize+ and /debug switches):

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.

Additionally:

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.

He also has another article entitled PDB Files: What Every Developer Must Know that is also a good read.

adrianbanks