Sign in to follow this  
Hibbs

C# Performance tips

Recommended Posts

Hibbs    126
Does anyone know of some tips or a specific resource for writing high performance c# code? I understand about avoiding boxing/unboxing, any other fundemental things i should avoid before getting to far in? Cheers

Share this post


Link to post
Share on other sites
Telamon    157
Depending on what you are doing, you might also try writing the performance critical code in C/C++ and linking it as a DLL. I did this for the second iteration of my perlin noise texture generator (source code) and I got a nice 5x-8x speedup (lots of integer math). Mileage may vary, but it was very easy to set up and get working.

Other than that, you can get the .Net 2.0 beta which has typed generics that will alleviate the boxing/unboxing problem.

Share this post


Link to post
Share on other sites
paulecoyote    1065
Perfomance tip #1 Get it all done, then and only then look for performance bottlenecks.

That said there's nothing wrong in follow heuristics as you go along, but it's better to write code you can understand and follow rather then sometimes brittle performance code. Then when it's done identify performance issues.

It is very easy to fall in to the premature optimisation trap... I know I have done in the past and probably will (despite knowing better) in the future.

Share this post


Link to post
Share on other sites
I don't think that's such a good performance tip. If you really get it all done and then notice that it's too slow for your needs there's a risk you might be screwed. I don't mean that you should optimize all the time, but you should definitely be aware of potential performance problems. A slow algorithm might be easy to replace but a "slow design" or general misuse of language features can be a lot harder to rework.

Share this post


Link to post
Share on other sites
helix    301
You both are right. It's important to design it properly up front so you have a good algorithm (etc) when you are finished that you can then optimize. But you don't want to be optimizing too much on the fly or your code will run the risk of becoming unreadable, buggy, etc. I don't really follow my own advice too well though...

Share this post


Link to post
Share on other sites

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