.NET isn’t a performance-first platform. It’s a productivity platform! Its goal is to allow us to write a bunch of business logic quickly without having to worry about the micro-details. Your code should just work, and be reliable. For the most part, this is a GOOD thing. My advice is to embrace that you don’t want to optimize every line of code you write. The juice simply won’t be worth the squeeze, so to speak.
But there are times where it’s important. If you are developing a library people are going to use as a foundation for their business logic (say System.Text.Json), you should be worrying about performance. If you are working on the critical hot-path processing in the core bits of your product, go ahead and do a round of performance analysis. If you are working on a library to export performance data out of an application (say OpenTelemetry), you certainly don’t want to add a bunch of performance overhead to do so.
What this series is going to be about is how you can analyze your code and write really high-performant logic in .NET to use in your libraries and products when it makes sense to do so.
Part 1: DynamicMethod as a high-performance alternative to Reflection.
Part 2: Enumerator performance surprises.