Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
07-04-2012, 05:55 AM
(This post was last modified: 07-04-2012, 05:56 AM by xoft.)
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?
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
07-04-2012, 06:36 AM
(This post was last modified: 07-04-2012, 06:37 AM by FakeTruth.)
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?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
07-04-2012, 05:41 PM
(This post was last modified: 07-04-2012, 05:50 PM by xoft.)
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
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
Maybe it's a problem with the specific settings the for cNoise.cpp file
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
07-28-2012, 09:18 PM
(This post was last modified: 07-28-2012, 09:24 PM by xoft.)
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.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
Nice
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
07-28-2012, 11:24 PM
(This post was last modified: 04-20-2015, 06:20 AM by NiLSPACE.)
Wow, 6 times faster!!! nice
but does that mean it uses 6 times more CPU/RAM??
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
|