0

I have a situation where I should track the FIRST changes applied to a field. This thing applies to "some" (10 if I'm not wrong) fields of a struct which I need to be as efficient as possible (it's a struct that will be intensively used to communicate information between threads for rendering/updating data; it's a message passing struct basically).

In this case I'm talking about xbox .net compact framework, I've heared that properties have performance issues because they are not inlined, so my question is:

What's the best way to face this situation?

2 Ideas:

1) I keep track of the first change done to a field, so I use a property that will automatically set a bit field to 1 to say "I've been changed!" (this bit field is part of a single int, so it's only a 4 byte overhead), but I'will waste all other calls to this property because they will simply change the value, because the bit is already set (until next frame obviusly)

2) I manually keep track of the change of the field (which will be public so), setting the bit with my own hands (more error possibilities but optimized)

Thanks for any suggestion

Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147

2 Answers2

1

The only "improved" way of doing (1) that I can imagine would be using delegates - keep two versions of the property set code, one that sets the bit field and one that doesn't. Then make the property use the second version after the bit has been set. That way you will avoid the overhead of always setting the bit field (but will get a smaller overhead of making a delegate call).

rsenna
  • 11,775
  • 1
  • 54
  • 60
  • I benchmarked the solution but a simple property call is 3 times slower than a public field usage... and I'm not on the compact framework but on the .net 4.0 (well the difference is 649 ticks against 274), On Xbox360 it's 3.4 times slower: 7734 ticks against 2265... quite high numbers against computer's! – Francesco Belladonna Dec 11 '10 at 18:47
  • This is not directly involved with question but custom operators are a performance disaster, if you sum 2 vectors with overloaded operators instead of summing their X and Y, you will get a 100 performance lost... what's up with this framework?!?! – Francesco Belladonna Dec 11 '10 at 19:23
  • 1
    @Fire-Dragon-DoL: what about directly calling the delegate, without the property? Still, if you are that much worried about performance, I guess you should stay with the public field... – rsenna Dec 13 '10 at 14:37
  • I'll stay with them, it's a problem with function calls (I looked around the Web)... so everything that involves a function call is "slow" (what did they think that I wouldn't use functions in a program?-.-)... thanks for your suggestion by the way – Francesco Belladonna Dec 16 '10 at 19:14
0

As rsenna stated, the only solution I found is staying with public fields or work with functions without worring so much about slow execution. There isn't a solution for this

Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147