Handmade Hero » Forums » Code » Compiler -O flag vs debug builds
Twicetimes
9 posts

None

#13521 Compiler -O flag vs debug builds
3 weeks, 5 days ago

When switching between optimised (-O2) and non-optimised (-Od) builds, the -O is usually all that Casey will change.

In %CommonCompilerFlags% we also specify -MTd, which tells the compiler to produce a debug multithreaded executable. However, in the linker flags for the game DLL, we specify -LD (not LDd, which is the debug equivalent). The compilation of the game DLL actually has both -MTd and -LD but I assume LD overrides it, as we get a .dll as output.

1) Is the -O flag the only thing which will make a significant difference in performance? Does a debug build built with -O2 run comparably to a non-debug build at -O2?

2) Are we deliberately making a debug version of the .exe and a non-debug version of the .dll for a particular reason?

None
mmozeiko
Mārtiņš Možeiko
1517 posts
1 project
#13522 Compiler -O flag vs debug builds
3 weeks, 5 days ago

1) Yes. Debug information does not cost anything in performance. You can have debug info with -O2 and it will run with exactly same performance as debug build without -O2.

2) Not sure which day are you looking at, but for latest source code as of now both exe and dll are built with exactly same O2/Od/Zi flags.
Twicetimes
9 posts

None

#13523 Compiler -O flag vs debug builds
3 weeks, 5 days ago Edited by on Nov. 15, 2017, 7 a.m.

Firstly, thanks for the insanely fast response.

mmozeiko
Not sure which day are you looking at, but for latest source code as of now both exe and dll are built with exactly same O2/Od/Zi flags.


Just checked the latest on github. Yes, the -O setting is the same for both .exe and .dll, but there's also -LD specified on the .dll compilation specifically.

Regarding the other debug-related flags, it looks like we're using -Z7 rather than -Zi (although this doesn't seem significant), and also -Zo (which I don't even see listed in https://docs.microsoft.com/en-gb/...ler-options-listed-alphabetically)

Anyway, thanks to your answer I know that even if there's debug info in the .exe and/or .dll, it's purely an issue of file size, not performance.

None
mmozeiko
Mārtiņš Možeiko
1517 posts
1 project
#13526 Compiler -O flag vs debug builds
3 weeks, 5 days ago Edited by Mārtiņš Možeiko on Nov. 15, 2017, 7:17 p.m.

LD is just a shortcut for cl.exe to make it pass /DLL to link.exe and to use /MT for cl.exe (which is default). You can skip using LD and then simply make sure you pass /DLL to link.exe.

/Zo is relatively new cl.exe argument that officially was introduced only in VS2015: https://msdn.microsoft.com/en-us/library/dn785163.aspx

But it was working also in VS2013. Just undocumented. In previous VS version (<2013) it was called /d2Zi+
Twicetimes
9 posts

None

#13528 Compiler -O flag vs debug builds
3 weeks, 5 days ago

Good to know, thanks.

None