Collection Performance: Using ForEachAsync() with List<>

The post demonstrates the usage of Parallel.ForEachAsync() with a List of reference types.

General Performance Tip: Enhanced Logging Approach

The article discusses advancements in logging techniques in .NET, particularly with the new source generator in .NET 6 that enhances performance using LoggerMessage. This new method improves logging efficiency by 11.25 times compared to previous approaches. It emphasizes the importance of extensive logging for issue resolution in code.

Collection Performance: Comparing Byte Array’s with SequenceEqual()

LINQ's SequenceEqual() method compares two Byte arrays, returning a Boolean indicating equal length and matching elements. Access more on collection performance by subscribing.

General Performance Tip: Handling Exceptions

In my presentation at the Silicon Valley Code Camp, a question about the performance of using the When() clause for catching exceptions prompted me to conduct performance testing. While traditional exception handling is crucial, my testing revealed that the When() clause is more performant when capturing multiple similar exceptions.

Collection Performance: Comparing ImmutableArray<>’s with SequenceEqual()

The ImmutableArrayExtensions contain a SequenceEqual() method for comparing ImmutableArray items. The method compares elements using the default equality comparer for TSource and can be used with a for() loop for performance validation.

General Performance Tip: Comparing ComputeHash(), HashData(), and TryHashData() Methods

Developers can simplify hashing byte arrays by using HashData() instead of ComputeHash(), as it requires less code and eliminates the need to manage the SHA256 object. Benchmarking shows HashData() is about 1.16x faster than ComputeHash() and 1.02x faster than TryHashData(). EditorConfig helps manage related diagnostics.

General Performance Tip: Creating an Object

In this investigation of object creation in .NET, various methods were explored, including "new" keyword, Activator.CreateInstance, and RuntimeHelpers.GetUninitializedObject.

General Performance Tip: Avoid Unnecessary Variable Initialization

In the analysis of code, it's noted that explicit initialization of variables, when the default state is already set, can impact performance. Situations requiring variable initialization are discussed, with examples showing unnecessary explicit initialization. The default values for reference types and the default values for properties of a custom type are also examined.

Coding Standards: Mastering Tuples in .NET

In .NET, tuples are immutable data structures that group multiple values of different types, simplifying code by avoiding custom classes. They are useful for returning or passing multiple values. Named tuples enhance readability but should not be overused. Accessing tuple elements can be done by position or via deconstruction.

String Performance: Comparing Strings with Globalization

In the String Performance chapter of the code performance book, the author demonstrates the usage of string.Compare() with StringComparison. Benchmark results are provided, along with a recommendation to use cultures or ordinals based on the strings being compared. The chapter also touches on setting up EditorConfig for dotnet_diagnostic.CA1862.