Optimizing DLLs
From Valve Developer Community
The Source SDK Visual Studios Projects properties and options are acceptable for many mods, but it can be made better and faster with some small changes to utilize Microsoft's optimizing C++ compiler. These changes produce code better tuned for newer processors without the need to re-write anything.
These changes are implemented by added extra switches and options to the property pages of your client and server projects. You can find this by selecting Project then Properties from the menu in the Visual C++ 2003 IDE.
| Table of contents |
Options
In the project properties page of your client and server, change these settings to optimize your DLL files.
General
- Whole Program Optimization - set to Yes.
Specifies that the program will be optimized across .obj boundaries.
C/C++
- Optimization -> Optimize for Processor - set to Pentium 4 and Above(/G7)
The G7 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/optimization.asp) flag produces code which is optimized for Pentium 4 processors and above which, in some cases can lead to a 10% improvement in execution speed. The code will still run on older processors, just not as fast.
- Code Generation -> Enable Enhanced Instruction Set - set to Streaming SIMD Extensions (/arch:SSE)
The arch (http://msdn2.microsoft.com/en-us/library/7t5yh4fd.aspx) flag enables the use of instructions found on processors that support enhanced instruction sets e.g., the SSE and SSE2 extensions of Intel 32-bit processors.
- Command Line -> Additional Options - add the switch /GL.
The GL (http://msdn2.microsoft.com/en-us/library/0zza0de8(VS.80).aspx) flag enables whole program optimization.
Linker
- Optimization -> Enabled COMDAT Folding - set to Remove Redundant COMDATs (/OPT:ICF)
/OPT:ICF (http://msdn2.microsoft.com/en-us/library/bxwfs976(VS.80).aspx) removes redundant COMDAT symbols from the linker output.
- Optimization -> Optimize for Windows98 - set to No (/OPT:NOWIN98)
/OPT:NOWIN98 (http://msdn2.microsoft.com/en-us/library/bxwfs976(VS.80).aspx) controls the section alignment in the final image. You should use this switch when building DLL's only for Windows NT, Windows 2000, Windows XP or later.
- Command Line -> Additional Options - add the switch /LTCG.
The /LTCG (http://msdn2.microsoft.com/en-us/library/xbf3tbeh(VS.80).aspx) option tells the linker to call the compiler and perform whole program optimization.
Notes
It will take longer for it to link the code, but it will run faster than with the default settings.
You can enable SSE (Streaming SIMD Extensions) optimizations due to the minium requirements of HL2 being a 1.2 GHz CPU, that defaults to a Pentium 4 or AMD Athlon processor that supports this technology.
External links
- Visual C++ Optimization Overview (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/optimization.asp)
- Compiler Options (http://msdn2.microsoft.com/en-us/library/9s7c9wdw(VS.80).aspx)
- Linker Options (http://msdn2.microsoft.com/en-us/library/y0zzbyt4(VS.80).aspx)

