Editorial Note: I originally wrote this post for the Monitis blog. You can check out the original here, at their site. While you’re there, have a look at the application monitoring options you can take advantage of.
First of all, make sure that you use StringBuilder when concatenating strings. You see, the “+” operator — just kidding. I mean, that’s not bad advice. Rather, I’m kidding in that I just don’t want to offer this style of tip today.
Often, advice about application performance comes at you with the staccato of rapid fire tips. “37 Ways to Shave Nanoseconds off of Your Overnight ETL Process.” I exaggerate for comedic effect with that title, perhaps. But the point remains. Authors serve up advice for optimization with many tips that matter only inside of tight loops. And it’s hard to keep all of those in your head.
I’d like to take a different tack here today and offer fewer suggestions in the hope that they’ll stick with you. But I differentiate my message in another crucial way as well. I want to offer performance tips for .NET programming that will also help you write clean, readable code.
All too often, these concepts stand in opposition to one another. Performance tips often demand changes that produce the desired effect while making the code harder to read. This phenomenon gives rise to the iconic wisdom that “premature optimization is the root of all evil.” Implementing them might bring relatively insignificant marginal gains in performance while creating confusing, hard-to-read code.
But it strikes me that readable and performant sometimes overlap. And, since tips for that serve two purposes, they are definitely worth filing away.