• Advertisement

# Script Scope Performance

This topic is 2538 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:
 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.

#### Share this post

##### Share on other sites
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.

#### Share this 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

##### Share on other sites
Thanks! I will test these properly with the older version when I get the chance.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### Popular Tags

• Advertisement
• ### Popular Now

• 45
• 11
• 17
• 11
• 13
• Advertisement