C# optimization trick

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

Hi,

I've read that the if/else statement, or get/set accessor, can be
compiled inline by the C# compiler if they are small enough.

Have you seen any documentation that 'summarized' all thoses
optimizations tricks? I would like to be aware of all tips and trick
that should be used as good programming habits that make any software
coding optimized. I remember that in VB6 there was a lot of
optimization tips.

So my question does not concern solving bottleneck inside an algorithm,
but tricks related on the language itself.

If you have any idea, that would be very appreciated, thanks!

Regards,
Marty
 
Hi Peter,

I had a look and it seem to have a lot of content, I'll read it all.

Thank you very much :)
Marty
 
Marty said:
I've read that the if/else statement, or get/set accessor, can be
compiled inline by the C# compiler if they are small enough.

No, they get inlined by the JIT - that's slightly different. In
particular, it's not a C# trick, it would happen in VB.NET too, for
instance.
Have you seen any documentation that 'summarized' all thoses
optimizations tricks? I would like to be aware of all tips and trick
that should be used as good programming habits that make any software
coding optimized. I remember that in VB6 there was a lot of
optimization tips.

So my question does not concern solving bottleneck inside an algorithm,
but tricks related on the language itself.

If you have any idea, that would be very appreciated, thanks!

I think it's more a case of *platform* "tricks" than language tricks.
For instance, you really ought to (and probably already do) know about
StringBuilder:
http://www.pobox.com/~skeet/csharp/stringbuilder.html

Is that the kind of thing you're after? I'll think about some more.
 
Marty said:
Hi,

I've read that the if/else statement, or get/set accessor, can be compiled
inline by the C# compiler if they are small enough.

Have you seen any documentation that 'summarized' all thoses optimizations
tricks? I would like to be aware of all tips and trick that should be
used as good programming habits that make any software coding optimized.
I remember that in VB6 there was a lot of optimization tips.

1. It's the JIT compiler that does it at runtime from the IL bytes not the
C# compiler.
2. How does it help you to optimize your accessors? Surely they already
contain as much code as they need to and no more.
3. As a general guidline you should use methods rather than properties where
a lot of work is involved. It's not a rule but people will assume that
property access is always efficient.
 
Hi Jon,

Thanks for the correction about C# compiler and JIT. Yes, this is the
kind of optimization trick I am looking for.

Regards
Marty
 
Back
Top