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

dotNetDave Story: The Critical Importance of Addressing Performance Before Product Release,' I recount a personal anecdote from my time at a San Diego-based company, highlighting the consequences of overlooking performance issues prior to release. Despite raising concerns, the failure to address these issues resulted in customer loss and ongoing struggles to improve performance post-launch.

String Performance Tip: Verifying if an Object is a String

The post explains two methods to confirm if an object is a string. It provides code examples for both methods and states that the first method is 1.17 times more efficient than pattern matching.

General Performance Tip: Constant vs Read-Only Property

It is recommended to use constants for static numerical or string values in code. This helps maintain code clarity and adhere to best practices. Benchmark tests show variables are slightly more performant than constants, but it is still advisable to use constants where appropriate to reflect the intent of the variable.

General Performance Tip: Generating Random Numbers

.NET's Random type has been a popular choice for generating random numbers. However, using RandomNumberGenerator for this purpose can result in a six-fold performance improvement, as shown in benchmark tests. Both methods allocate the same amount of memory.

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: Retrieving the Process Id

When working with .NET, developers can obtain the initiating process ID using either Process.GetCurrentProcess().Id or System.Environment.ProcessId. Benchmark tests show that the former is slightly more performant. Additionally, the setup for this is specified in EditorConfig as a suggestion for code quality.

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.