I just started a rather ambitious economy simulation project where I have to loop a lot through various arrays/structs, some of them with constant values. When looking for a way to optimize perfomance right from the start, I stumbled upon loop unrolling:
The value assignments for my arrays are generated within an VBA automated excel sheet, so I can change values and generate new unrolled loops very fast.
But I am curious, has anyone of you tested loop unrolling with Galaxy to find out if there is any relevant performance advantage? Or will the Galaxy compiler do this for me by itself?
I would not consider loop unrolling until you have a finished version of the script. Stuff like loop unrolling is so low-level, that you should never do it manually. Not until you have exhausted every other algorithmic improvement possible and profiling indicates that that specific loop is a the bottleneck or a big part of it.
And after you tried optimizing code at such a low level do another performance test to see if what you changed actually improved things.
Reasons for this are that undoing loop unrolling is harder than unrolling a loop, the overhead of loops is minimal at best, so only the tiniest loop bodies are worth unrolling, and you might be focusing on these micro-optimizations before actually having exhausted algorithmic improvements, which usually provide far better benefits.
You are better off using Amdahl's law when trying to optimize your code. Find the biggest bottleneck, and improve that. This will have the biggest effect on your performance. So pretty much what Deaod said because most of the time it's your algorithms. The galaxy compiler also probably automatically unrolls your loops because modern compilers do it behind the scene.
Also consistent readable code is by far better than unreadable code. Less room for bugs, which means less development time. (Unless you are making some sort of standard library, which is not the Starcraft2 mod scene)
Of course loop unrolling will screw readability and there are more obvious methods to improve performance, but I simply wanted a second opinion on that. As the map will be SP only (at least for the prototype), maybe there won't be any performance issues after all.
Hey,
I just started a rather ambitious economy simulation project where I have to loop a lot through various arrays/structs, some of them with constant values. When looking for a way to optimize perfomance right from the start, I stumbled upon loop unrolling:
e.g.
becomes
The value assignments for my arrays are generated within an VBA automated excel sheet, so I can change values and generate new unrolled loops very fast.
But I am curious, has anyone of you tested loop unrolling with Galaxy to find out if there is any relevant performance advantage? Or will the Galaxy compiler do this for me by itself?
Didnt test it, but performing loop unrolling by hand seems ridiculous to me. The advantage is minimal.
Yeah, that's what I thought, too. And, God forbid, I would probably hit the script limit pretty soon :)
I would not consider loop unrolling until you have a finished version of the script. Stuff like loop unrolling is so low-level, that you should never do it manually. Not until you have exhausted every other algorithmic improvement possible and profiling indicates that that specific loop is a the bottleneck or a big part of it.
And after you tried optimizing code at such a low level do another performance test to see if what you changed actually improved things.
Reasons for this are that undoing loop unrolling is harder than unrolling a loop, the overhead of loops is minimal at best, so only the tiniest loop bodies are worth unrolling, and you might be focusing on these micro-optimizations before actually having exhausted algorithmic improvements, which usually provide far better benefits.
You are better off using Amdahl's law when trying to optimize your code. Find the biggest bottleneck, and improve that. This will have the biggest effect on your performance. So pretty much what Deaod said because most of the time it's your algorithms. The galaxy compiler also probably automatically unrolls your loops because modern compilers do it behind the scene.
Also consistent readable code is by far better than unreadable code. Less room for bugs, which means less development time. (Unless you are making some sort of standard library, which is not the Starcraft2 mod scene)
Hey, thanks for the input!
Of course loop unrolling will screw readability and there are more obvious methods to improve performance, but I simply wanted a second opinion on that. As the map will be SP only (at least for the prototype), maybe there won't be any performance issues after all.
Premature optimization is the root of all evil ;)