Visual studio "optimization' wtf - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Development (https://forum.cuberite.org/forum-13.html) +--- Thread: Visual studio "optimization' wtf (/thread-504.html) |
Visual studio "optimization' wtf - xoft - 07-04-2012 I was wondering why generation was slow. Then I looked at the code that VS is generating for the hottest function in our code, cNoise::IntNoise3D(). And I could only wonder: WTF??? Such code in a release build? Aren't we doing something wrong if this is the "optimized" code? I've always thought compilers were better than this. I wonder how gcc is doing in this function, any *nix geeks out there who could help dig the asm listing of that function out of gcc or gdb? RE: Visual studio "optimization' wtf - FakeTruth - 07-04-2012 I'm a total noob @ assembly, but if you know how it works you could simply inline some asm and optimize it yourself? Also maybe it'll optimize it properly if you put it between parentheses? RE: Visual studio "optimization' wtf - xoft - 07-04-2012 I've got an even easier "fix": putting the 57*57*57 into parenthesis made VS emit the optimized code Even weirder - if I pull that function out into a standalone project for testing, the optimizer works wonders - for a few calls with constants, it even replaced the calls with the constant results; in other cases, it inlined the function and optimized it much better. It seems something's wrong with our project RE: Visual studio "optimization' wtf - xoft - 07-05-2012 I tried with VC2010, and whaddya know, it produces the very same stupid code, doing three multiplications one right after another. However, when I pulled only the cNoise sources and all the headers they depend on from MCServer into a clean new project, added a few testcases into a main() function, then the code optimized nicely, both with 2008 and 2010. Weird. RE: Visual studio "optimization' wtf - FakeTruth - 07-05-2012 Maybe it's a problem with the specific settings the for cNoise.cpp file RE: Visual studio "optimization' wtf - xoft - 07-05-2012 I tried compiling Rev 180 which didn't have the specific settings, still no good. It's no use, there hasn't been a time when that function was optimized on MCServer, so I can't find the culprit by walking through history. Pity. RE: Visual studio "optimization' wtf - xoft - 07-28-2012 Finally, after all this time, I found out what the culprit was (kinda - I know how it manifests and how to work around it, but not the root cause). It was in the project setting, but something weird seems to be going on: In the Project options -> Configuration Properties -> C/C++ -> Optimization -> Optimization, it said "Maximize speed (/O2)", and the value was not bold, indicating a default of some kind. However, when the compiler ran, it got the "Disabled (/Od)" option instead, because that is the true default. Dunno where the mixup came from, but when I changed the value to "Full Optimization (/Ox)", it suddenly generates fully optimized code. Yay! Wow! Just... wow! The generator is now soooo fast!!! There's about a 6x speedup! I get more than 100 chunks generated per second, instead of the regular ~20 per second. RE: Visual studio "optimization' wtf - FakeTruth - 07-28-2012 Nice RE: Visual studio "optimization' wtf - NiLSPACE - 07-28-2012 Wow, 6 times faster!!! nice but does that mean it uses 6 times more CPU/RAM?? RE: Visual studio "optimization' wtf - xoft - 07-29-2012 No, it uses the same amount of everything (meybe even a bit less), it's just that the compiler finally does what it's supposed to do. |