Optimization for speed in VS 2008

Discussion of chess software programming and technical issues.

Moderator: Ras

Engin
Posts: 1001
Joined: Mon Jan 05, 2009 7:40 pm
Location: Germany
Full name: Engin Üstün

Optimization for speed in VS 2008

Post by Engin »

hello,

i am nothing doing so far a good speed optimization on Visual Studio Compiler with my Tornado chess engine, so the NPS are very slow.

if i see Crafty speed i am wondering how this can happen, or scorpio too

i ask one time Jim Aplett to help me, but i dont understand really what he means, on the other hand i want not to give him my sources to compiling him self.

he hint me to compile with PGO too , but this is only a small increase of speed i get.

now i need your helps to do Tornado for more speedup, if any want to help me.

PGO work with x64 fine, but with w32 i get an exception error :( , why ?


my configuration so far on VS 2008:

w32 command lines:

code generation:

/O2 /Ob2 /Oi /Ot /GT /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /GF /FD /EHsc /MT /Zp16 /Gy /fp:fast /GR- /Fo".\Release/"
/Fd".\Release/" /W2 /nologo /c /TP

linker:

/OUT:".\Release/TornadoChess_w32.exe" /NOLOGO /MANIFEST /MANIFESTFILE:".\Release\TornadoChess_w32.exe.intermediate.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Release/TornadoChess.pdb" /SUBSYSTEM:CONSOLE /LARGEADDRESSAWARE:NO /OPT:REF
/LTCG /MACHINE:X86 /PROFILE kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib odbc32.lib odbccp32.lib


x64 command lines:

code generation:
/O2 /Ob2 /Oi /Ot /GT /GL /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /GF /FD /EHsc /MT /Zp16 /Gy /fp:fast /GR- /Fo".\Release/"
/Fd".\Release/" /W2 /nologo /c /TP

linker:
/OUT:".\Release/TornadoChess_x64.exe" /NOLOGO /MANIFEST /MANIFESTFILE:"x64\Release\TornadoChess_x64.exe.intermediate.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:".\Release/TornadoChess.pdb" /SUBSYSTEM:CONSOLE /LARGEADDRESSAWARE /OPT:REF
/LTCG /MACHINE:X64 /PROFILE kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib odbc32.lib odbccp32.lib
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimization for speed in VS 2008

Post by bob »

Engin wrote:hello,

i am nothing doing so far a good speed optimization on Visual Studio Compiler with my Tornado chess engine, so the NPS are very slow.

if i see Crafty speed i am wondering how this can happen, or scorpio too

i ask one time Jim Aplett to help me, but i dont understand really what he means, on the other hand i want not to give him my sources to compiling him self.

he hint me to compile with PGO too , but this is only a small increase of speed i get.

now i need your helps to do Tornado for more speedup, if any want to help me.

PGO work with x64 fine, but with w32 i get an exception error :( , why ?


my configuration so far on VS 2008:

w32 command lines:

code generation:

/O2 /Ob2 /Oi /Ot /GT /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /GF /FD /EHsc /MT /Zp16 /Gy /fp:fast /GR- /Fo".\Release/"
/Fd".\Release/" /W2 /nologo /c /TP

linker:

/OUT:".\Release/TornadoChess_w32.exe" /NOLOGO /MANIFEST /MANIFESTFILE:".\Release\TornadoChess_w32.exe.intermediate.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Release/TornadoChess.pdb" /SUBSYSTEM:CONSOLE /LARGEADDRESSAWARE:NO /OPT:REF
/LTCG /MACHINE:X86 /PROFILE kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib odbc32.lib odbccp32.lib


x64 command lines:

code generation:
/O2 /Ob2 /Oi /Ot /GT /GL /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /GF /FD /EHsc /MT /Zp16 /Gy /fp:fast /GR- /Fo".\Release/"
/Fd".\Release/" /W2 /nologo /c /TP

linker:
/OUT:".\Release/TornadoChess_x64.exe" /NOLOGO /MANIFEST /MANIFESTFILE:"x64\Release\TornadoChess_x64.exe.intermediate.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:".\Release/TornadoChess.pdb" /SUBSYSTEM:CONSOLE /LARGEADDRESSAWARE /OPT:REF
/LTCG /MACHINE:X64 /PROFILE kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib odbc32.lib odbccp32.lib
As a general rule, this is more about programming itself, as opposed to compiler options. And you are probably not going to have much luck asking for help if you are not willing to provide your source code, since one can't fix what one can't see...
Engin
Posts: 1001
Joined: Mon Jan 05, 2009 7:40 pm
Location: Germany
Full name: Engin Üstün

Re: Optimization for speed in VS 2008

Post by Engin »

i am doing to make more speed in the source too :)

i using also a profiler to see where the problems is

i want only to see what option are other programmers using for speedup the whole source or help me what is wrong with my options that is all.

but many thx for answer me so quickly :)
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimization for speed in VS 2008

Post by bob »

Engin wrote:i am doing to make more speed in the source too :)

i using also a profiler to see where the problems is

i want only to see what option are other programmers using for speedup the whole source or help me what is wrong with my options that is all.

but many thx for answer me so quickly :)
My options are simple

-O2

I do use PGO.

One can play games (in gcc -fomit-frame-pointer and such) to gain a tiny bit here and there, but there are no 10%+ tricks (except for PGO).
rbarreira
Posts: 900
Joined: Tue Apr 27, 2010 3:48 pm

Re: Optimization for speed in VS 2008

Post by rbarreira »

If you don't know why your code is slow, profiling your code is the only thing you can do.
Milos
Posts: 4190
Joined: Wed Nov 25, 2009 1:47 am

Re: Optimization for speed in VS 2008

Post by Milos »

rbarreira wrote:If you don't know why your code is slow, profiling your code is the only thing you can do.
He's just asking for the best compiler line, why is everyone just preaching instead of helping?

Here is my w32 line (VS2008 compatible):

/O2 /Ob2 /Oi /Ot /Oy /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /FD /MT /Zp8 /arch:SSE2 /fp:fast /J /GR- /Fp".\Release/XXX.pch" /Fo".\Release/" /Fd".\Release/" /W3 /nologo /c /Z7 /TC /errorReport:prompt

and for linker:

/OUT:".\Release/XXX.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:".\Release\XXX.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Release/XXX.pdb" /LTCG /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimization for speed in VS 2008

Post by bob »

Milos wrote:
rbarreira wrote:If you don't know why your code is slow, profiling your code is the only thing you can do.
He's just asking for the best compiler line, why is everyone just preaching instead of helping?

Here is my w32 line (VS2008 compatible):

/O2 /Ob2 /Oi /Ot /Oy /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /FD /MT /Zp8 /arch:SSE2 /fp:fast /J /GR- /Fp".\Release/XXX.pch" /Fo".\Release/" /Fd".\Release/" /W3 /nologo /c /Z7 /TC /errorReport:prompt

and for linker:

/OUT:".\Release/XXX.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:".\Release\XXX.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Release/XXX.pdb" /LTCG /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Perhaps because compiler options (assuming basic optimizations are enabled) are not going to make a big difference, and he seems to be far slower than he expects. It's not a compiler issue.
Dann Corbit
Posts: 12799
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Optimization for speed in VS 2008

Post by Dann Corbit »

Algorithm changes will be most significant.

Some simple mechanical things to look for:
1. If you pass big classes or structs in your code as arguments to methods or functions, and you do not modify them with a need to keep the modifications, pass them as const references. Otherwise, a complete duplicate structure is created and passed on the stack. You may also wish to pass classes or structs by address if you need to modify the contents for use later.

2. If you have a big table of stuff initialized at the start of a function, make it static const and then the compiler will do it at compile time and it won't have to do anything when you enter the function.

Most of the mechanical things we used to have to do to make code faster are now done for us by the compiler, even elimination of tail recursion.

Once profiling shows you where your code is slow, look for ways to write a better algorithm. By far, this is the right way to make it faster.
Milos
Posts: 4190
Joined: Wed Nov 25, 2009 1:47 am

Re: Optimization for speed in VS 2008

Post by Milos »

bob wrote:Perhaps because compiler options (assuming basic optimizations are enabled) are not going to make a big difference, and he seems to be far slower than he expects. It's not a compiler issue.
Depends what you call a big difference. I have sometimes experienced 10-15% difference between the full optimization line and just /O2.
On many cases I don't get more than 5% with PGO.
So it's all relative.
And yes, I'm talking about VS2008.
rbarreira
Posts: 900
Joined: Tue Apr 27, 2010 3:48 pm

Re: Optimization for speed in VS 2008

Post by rbarreira »

He's just asking for the best compiler line, why is everyone just preaching instead of helping?
He already said he wasn't happy with the improvement from things like PGO. Given that, I didn't think that he'd be happy with any other flags either.