Analyzing Code for Issues: Visual Studio Analyze

Analyze has been available in most of the Visual Studio editions for a long time and is based on FxCop. This article will discuss how to set it up and use it properly.

Serializing Objects: JSON Serialization

The article explores the significance of object serialization into JSON format, comparing Newtonsoft.Json and JsonSerializer in .NET.

Collection Performance Under Load: for() and foreach()

Let’s discuss for() and foreach() under load to establish a baseline. As you can see below, I used the same code in the previous chapter and added Task.Delay() to simulate a CPU load.

String Performance: String Comparison

The article discusses the importance of choosing the right string comparison method in coding, emphasizing the use of ToUpperInvariant() for accurate globalized comparisons, and presents benchmark results showing its performance advantage. It also briefly mentions the comparison between the == operator and Equals() for checking string equality. Updated January 2024.

Collection Performance: Looping Over a Collection

There are four main ways to loop through a collection by using for(), foreach(), do() and while(). Let’s see which one of these methods are the most performant along with using the generic ForEach() method. Updated September 2023.

Reference Type & Structure Performance: Best Practices

General best practices for types. Updated January 2023.

Reference Type & Structure Performance: Disposable Types

The article emphasizes the critical importance of addressing IDisposable issues in code assessments, highlighting common problems such as virtual memory leaks, unreleased file handles, and escalated database connections. The author provides solutions to two prevalent issues: neglecting to call Dispose() on disposable types and failing to implement the IDisposable interface. Additionally, the author introduces three extension methods from their open-source assembly, Spargine, designed to simplify the disposal of types and mitigate potential memory issues in large collections.

Structure Performance: Implementing Operators

The post discusses the necessity of implementing equality operators (== and !=) for structures, as they do not have inherent implementations. Providing an example, it highlights the ease of this process using refactoring tools like CodeRush. The author recommends consistently implementing these operators and mentions configuring code analysis in EditorConfig.

Reference Type & Structure Performance: Override Object Virtual Methods

This content discusses optimizing performance for reference types and structures in .NET. It emphasizes the importance of understanding memory allocation and recommends overriding methods and operators in structures. The author stresses the need for careful benchmarking before making overrides.

General Performance Tip: Using Statements and Unused References

This article series provides crucial coding tips for improving performance, emphasizing the impact of small changes when handling high message volumes. It advises on removing unnecessary using statements to streamline code and improve type creation. The CodeRush refactoring tool or manual removal methods are recommended. Further details can be found in the "Analyzing Code for Issues" chapter of a code performance book.