0

I've been assigned to a large legacy project, which can only be deployed in debug version, due to various historical (and stupid) reasons. As one might expect, there are some performance issues.

The project is written in C, Visual Studio 6 (yes, that old). I'm looking for ways to minimize the impact of "everything is in debug version". Are there any compiler or linker options which would minimise the amount of debug code injected into the final binary? Or is there an external utility which could strip some of it later on?

(I know this is basically a silly question, and that we're supposed to switch to release, but trust me, this is completely out of my control..and it kills a part of my soul virtually every day.)

dr Hannibal Lecter
  • 6,665
  • 4
  • 33
  • 42

1 Answers1

2

First of all, you should list all the differences between the debug and the release versions and try to identify the things that you can change and the things that you cannot. Then just change all the things you are allowed.

From the top of my head, if my memory serves me correctly:

  • Debug: link with debug DLLs. Release: link with release DLLs.
  • Debug: compile without any optimization. Release: compile with all optimizations.
  • Debug: compile with assertions (-D_DEBUG). Release: compile without assertions (-DNDEBUG).
  • Debug: compile/link with debugging symbols. Release: compile/link without debugging symbols (not really an impact on performance).
  • Any arbitrary changes the original developers made to the project configuration.

From all of these, only the first two should really be able to make a difference. The DLL because you depend on the debug DLL for some (silly) reason. And the second one because the optimizations can cause subtle bugs in the program to show themselves.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • Thanks for this. Obviously, I can't do much really..I have a debug module linking to other debug modules, and that can't be changed (unfortunately). So I guess all the 'relevant' options are not really available :-\ – dr Hannibal Lecter Mar 16 '12 at 16:32
  • The optimization level should not depend on what you are linking with. There is no technical reason that compiling all future debug builds with optimizations enabled would cause linking or run-time problems. "Executive" reasons may be another matter. – AShelly Mar 16 '12 at 21:46
  • As I tried to say, and AShelly told better, every bullet in my list is independent of the others and can be enabled/disable on their own. If what matters is to link to the debug DLLs, you could still optimize _your_ code while linking with their non-optimized one. – rodrigo Mar 17 '12 at 00:35
  • I think I understand what @AShelly and you are saying here, but if I compile with optimizations I no longer have a debug module. Or at least, I don't have suffient knowledge to do that. VC6 only gives me optimization options when debug is disabled; or alternatively, I'm not reading the settings right. – dr Hannibal Lecter Mar 19 '12 at 15:57
  • @drHannibalLecter - You are mixing things up. VC6 by default gives you two build configurations: "Debug" and "Release", with a bunch of options set up for _debugging_ and _releasing_ respectively. But nothing prevents you to edit those configurations and change _anything_ you want: you can enable optimizations in "Debug" or disable them in "Release", etc. Alternatively you can create a whole new build configuration (say "Test") and configure it exactly as you want: you just have to know what you want (or need). – rodrigo Mar 19 '12 at 16:56
  • I only have VS8 on my desktop, so some options may differ slightly, but select the Debug build, then go to Properties/Optimization andselect "Full Optimization", "Enable Intrinsics". Under Code Generation, turn off "Basic Runtime Checks. Under Preprocessor Definitions, change "_DEBUG" to "NDEBUG". This will give you a debugable optimized build. Note that the optimization will sometimes cause behavior that appears odd: lines seemingly executed out of order, or skipped entirely, local variables not available. However this is a true look at what the optimizer is doing. It's educational. – AShelly Mar 19 '12 at 17:04