Re: Data oriented programming

Phill Djonov <[email protected]> Fri, 8 Oct 2010 14:55:31 -0600
Newsgroups gmane.games.devel.sweng
Message-ID <[email protected]>
Well, even just transforming:

foreach( object )
{
    //not real function calls, just illustrating the flow of the loop
    //if it helps, imagine them all messy and interleaved :)
    temp;
    FollowPointersAround( object, temp );
    BranchyFixingUpOfData( temp );
    HeavyNumberCrunching( temp );
}

into:

temp[]
for( ... )
    FollowPointersAround( objects[index], temp[index] ); //effectively
what we're referring to as a "copy"
for( ... )
    BranchyFixingUpOfData( temp[index] );
for( ... )
    HeavyNumberCrunching( temp[index] );

is a win.

It's *much* easier to go into each of those separate loops and measure
and optimize than it is the first. Loops are smaller and highly
focused. Logic mispredictions don't stall the math pipeline. Fewer
temporaries are in play, freeing registers, making unrolling
opportunities more obvious. It makes sense to do expensive
pipeline/cache-flushing CPU-mode switches between stages, or to
utilize write-combining, scratch pads, or other special hardware
features. That sort of stuff can *easily* make up for the cost of
pushing the original temp out of registers or the stack, and often
would even if everything Richard and Fabian said about mitigating copy
costs were false.

And, when the profiler screams, or you move to a new platform, you can
likely fix things in isolation without having to butcher "object" and
every other bit of code that touches it.

Phill

On Fri, Oct 8, 2010 at 7:52 AM, Richard <[email protected]> wrote:
>
> In article <[email protected]>,
>    Warrick Buchanan <[email protected]> writes:
>
>> Also I would add to that and say don't be afraid of copying data around
>> [...]
>
> The reasoning behind this being that the cache misses during copying is
> paid for by the repeated cache hits during subsequent processing?
>
> Does this assume that the data needs to be accessed more than once
> during processing?
> --
> "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
>  <http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>
>
>      Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
> _______________________________________________
> Sweng-Gamedev mailing list
> [email protected]
> http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com
>
_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com