General Performance Tips

To enhance the performance of .NET applications, developers should focus on mastering key techniques rather than relying on quick fixes. This resource offers a comprehensive collection of practical, evidence-based tips covering a range of topics, from memory management to coding patterns, aimed at creating efficient, robust applications ready for production.

Reference Type & Structure Performance: Hashing Classes, Records, and Structures

A SHA256 hash can be generated for a class, record, or structure using a specific code. Performance analysis shows that hashing a class is 1.032 times faster than a structure and 1.048 times more efficient than a record. The memory allocations for record, reference, and value types are also provided in bytes.

General Performance Tip: Cloning Various Types

The post discusses the process of cloning different types of objects, with Microsoft recommending the use of JSON serialization for this purpose. The author explores the performance differences in cloning reference types, value types, and record types. Benchmark results using JsonSerializer reveal that cloning reference types is 1.015 times faster than cloning record types and 1.24 times more performant than cloning value types. The findings are shared for reference.

String Performance: Optimizing String Substring Extraction – Slicing vs. AsSpan()

The content presents an alternative approach to obtaining a substring using slicing with ReadOnlySpan and AsSpan() methods.

Rockin’ the Code World Season 4: Special Guest Milan Jovanović 

I hope you will join me on Saturday, May 5th, 2024, at 10:00 PST on C# Corner TV for show #101! For the second time, my very special guest will be Milan Jovanović, Software Architect, .NET Content Creator.

General Performance Tip: Optimizing Method Returns

When customizing attributes, Microsoft and I both advise sealing them for clarity and performance. However, benchmark results show sealing attributes to be marginally less performant, with both outcomes indicating a memory allocation of 24 bytes. Despite this, I maintain that sealing non-inheritable classes is essential for robust class design.

Collection Performance: Comparing Key Search Methods in Dictionaries

The post discusses two methods for searching a specific key in a Dictionary. The ContainsKey() method is recommended by Microsoft for improved performance but is it more performant?

dotNetDave Story: The Critical Importance of Addressing Performance Before Product Release

A true story illustrates the critical importance of addressing performance issues before a product launch. Despite warnings about potential negative impacts on customer experience, management dismissed these concerns. Ultimately, post-launch attempts to fix performance didn’t resolve the damage done, emphasizing that performance must be prioritized throughout the development process.

Boosting Performance and Memory Efficiency: Introducing ToDelimitedString() with Source Generators in Spargine

The article introduces a method called ToDelimitedString() in programming, using a StringBuilder and commas to create a delimited string. Benchmark results indicate that this method is 1.23 times more performant and allocates less memory, thanks to the utilization of a source generator in Spargine.

Optimizing String Processing in Collections: The Impact of PerformAction() in Spargine and FastStringBuilder

This article explores the optimization of string processing in collections through the integration of the PerformAction() method in Spargine and FastStringBuilder. Demonstrating a 1.79-fold performance increase and reduced memory allocation, the method proves to be a valuable tool for developers seeking enhanced efficiency in string manipulation.