Optimizing DLLs: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
Line 1: Line 1:
The default release mode that comes with the Source SDK's Visual Studios Projects is acceptable for many mods, but it can be made better and faster with some small changes.
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 utilise Microsoft's optimising C++ compiler. These changes produce code better tuned for newer processors without the need to re-write anything.


In the project properties page of your client and server, change these settings to optimize your DLL files.
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.
{{note|Don't forget to add these options in both the '''client''' and '''hl''' properties}}


#''General''<br>Whole Program Optimization 'yes'{{note|Memory requirements can be very high when compiling with ''Whole Program Optimization'' on}}
== Options ==
#''C/C++ add these two switches to the 'command line''':<br>/GL /G7
#''Link add these three switches to the 'command line''':<br>/OPT:ICF /OPT:WIN98 /LTCG{{note|You should only need to use /LTCG if you built the vgui_controls.lib with the fixes.}}


In the project properties page of your client and server, change these settings to optimise your DLL files.
=== General ===
*''Whole Program Optimization'' - set to '''Yes'''.<br>Specifies that the program will be optimised across .obj boundaries.{{note|Memory requirements can be very high when compiling with ''Whole Program Optimization'' on}}
=== C/C++ ===
*''Optimization'' -> ''Optimize for Processor'' - set to '''Pentium 4 and Above(/G7)'''<br>The [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/optimization.asp G7] flag produces code which is optimised 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)'''<br>The [http://msdn2.microsoft.com/en-us/library/7t5yh4fd.aspx arch] 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.{{note|Be careful with this setting as it will prevent the code running on processors which don't support these extensions}}
*''Command Line'' -> ''Additional Options'' - add the switch '''/GL'''.<br>The [http://msdn2.microsoft.com/en-us/library/0zza0de8(VS.80).aspx GL] flag enables whole program optimisation.
=== Linker ===
*''Optimization'' -> ''Enabled COMDAT Folding'' - set to '''Remove Redundant COMDATs (/OPT:ICF)'''<br>[http://msdn2.microsoft.com/en-us/library/bxwfs976(VS.80).aspx /OPT:ICF] removes redundant COMDAT symbols from the linker output.
*''Optimization'' -> ''Optimize for Windows98'' - set to '''Yes (/OPT:WIN98)'''<br>[http://msdn2.microsoft.com/en-us/library/bxwfs976(VS.80).aspx /OPT:WIN98] aligns code on 4K boundaries which improves performance on Windows 98 and later systems.
*''Command Line'' -> ''Additional Options'' - add the switch '''/LTCG'''.<br>The [http://msdn2.microsoft.com/en-us/library/xbf3tbeh(VS.80).aspx /LTCG] option tells the linker to call the compiler and perform whole program optimisation.{{note|You should only need to use /LTCG if you built the vgui_controls.lib with the fixes.}}
== Notes ==
It will take longer for it to link the code, but it will run faster than with the default settings.
It will take longer for it to link the code, but it will run faster than with the default settings.


You can also 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 that support this technology. This can be found under the ''Code Generation'' setting.
You can enable SSE (Streaming SIMD Extensions) optimisations 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 ==
*[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/optimization.asp Visual C++ Optimization Overview]
*[http://msdn2.microsoft.com/en-us/library/9s7c9wdw(VS.80).aspx Compiler Options]
*[http://msdn2.microsoft.com/en-us/library/y0zzbyt4(VS.80).aspx Linker Options]
 
 
[[category:programming]][[category:tutorials]]
[[category:programming]][[category:tutorials]]

Revision as of 12:09, 3 June 2006

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 utilise Microsoft's optimising 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.

Note.pngNote:Don't forget to add these options in both the client and hl properties

Options

In the project properties page of your client and server, change these settings to optimise your DLL files.

General

  • Whole Program Optimization - set to Yes.
    Specifies that the program will be optimised across .obj boundaries.
    Note.pngNote:Memory requirements can be very high when compiling with Whole Program Optimization on

C/C++

  • Optimization -> Optimize for Processor - set to Pentium 4 and Above(/G7)
    The G7 flag produces code which is optimised 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 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.
    Note.pngNote:Be careful with this setting as it will prevent the code running on processors which don't support these extensions
  • Command Line -> Additional Options - add the switch /GL.
    The GL flag enables whole program optimisation.

Linker

  • Optimization -> Enabled COMDAT Folding - set to Remove Redundant COMDATs (/OPT:ICF)
    /OPT:ICF removes redundant COMDAT symbols from the linker output.
  • Optimization -> Optimize for Windows98 - set to Yes (/OPT:WIN98)
    /OPT:WIN98 aligns code on 4K boundaries which improves performance on Windows 98 and later systems.
  • Command Line -> Additional Options - add the switch /LTCG.
    The /LTCG option tells the linker to call the compiler and perform whole program optimisation.
    Note.pngNote:You should only need to use /LTCG if you built the vgui_controls.lib with the fixes.

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) optimisations 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