Script Scope Performance

Started by
2 comments, last by arpeggiodragon 13 years, 1 month ago
Hi. I've been getting some minor performance discrepancies with different scripts so I've been experimenting to try and minimize this. What I've found for value types is this:

-Using this as a base for comparison:

float x = 0;
float y = 0;
float xx = 1;
float yy = 2;
for(int i=0;i<100000;++i)
{
x = xx; //simple assignment test.. this is actually pretty fast for built in value types!
y = yy;
xx = x;
yy = y;
}


3x slower

Vector2 a;
Vector2 b;
for(int i=0;i<100000;++i)
{
a.x = b.x;
b.x = a.x;
a.y = b.y;
b.y = a.y;
}




This is still very fast. Only 2.1 times slower than the base test:

Vector2 a;
Vector2 b;
for(int i=0;i<100000;++i)
{
a = b; //evaluates to a function call.
b = a;
}



8x slower ???

class test
{
Vector2 a;
Vector2 b;
void run()
{
for(int i=0;i<100000;++i)
{
a = b; // a, b are now class members, same speed as if declared global
b = a;
}
}
}



also 8x slower

class V
{
Vector2 v;
}

V a;
V b;
for(int i=0;i<100000;++i)
{
a.v = b.v;
b.v = a.v;
}

Tested these in release using windows performance timers.

Is this expected in terms of speed? -Also wondering if there's any tricks to get class members to be better 'cached' when executing a function within that class? (I use a lot of classes)

Thanks.
Advertisement
I'll have a look at these samples. I know for a fact that there is still a lot of room for optimization in the generated byte code.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hi. I've checked in some bytecode optimizations that should even out the field a bit between these different scenarios, and even improving the performance of the base scenario. You'll find it in revision 830.

There might be more performance that can be squeezed out of these scenarios, however I need to move on to other things. But, should you find other scenarios that seems oddly slow please let me know and I'll have a look at it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks! I will test these properly with the older version when I get the chance. :)

This topic is closed to new replies.

Advertisement