Sign in to follow this  

Script Scope Performance

This topic is 2463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
[code]
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;
}
[/code]

3x slower
[code]
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;
}
[/code]



This is still very fast. Only 2.1 times slower than the base test:
[code]
Vector2 a;
Vector2 b;
for(int i=0;i<100000;++i)
{
a = b; //evaluates to a function call.
b = a;
}
[/code]


8x slower ???
[code]
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;
}
}
}
[/code]


also 8x slower
[code]
class V
{
Vector2 v;
}

V a;
V b;
for(int i=0;i<100000;++i)
{
a.v = b.v;
b.v = a.v;
}
[/code]
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this