Collection Performance: Memory Efficiency with AsMemory() in Byte Array Conversion

The article discusses the efficiency benefits of using AsMemory() for byte array conversion, emphasizing reduced memory usage, future-proofing code, and performance optimization. Benchmark results highlight a significant performance advantage, with a 54 times improvement compared to other methods, reinforcing the importance of AsMemory() for optimal performance in memory-sensitive applications.

Collection Performance: Converting Byte Array to Memory<> and ReadOnlyMemory<>

When working with byte arrays, there are two methods to convert to Memory. Using AsMemory() offers performance optimization, efficient memory management, improved code clarity, and future-proofing. Benchmark results show a 57x performance improvement, with no memory allocation. This method is crucial for memory-sensitive applications and large datasets. Utilize AsMemory() for optimal performance and efficient array handling.

Collection Performance: Exploring the Performance Impacts of Array Properties

The post critiques developers’ practices of using properties that return arrays, highlighting issues like lack of encapsulation, read-only enforcement challenges, and limited flexibility for future changes. It recommends using methods or collections as alternatives, despite performance benchmarks indicating that array properties are more efficient, ultimately suggesting adherence to Microsoft's guidelines.

Collection Performance: Finding First or Last and Count

Many developers use LINQ methods such as First(), Last(), and Count() to interact with collections. However, these methods can be about 2.33Ă— slower in performance compared to direct indexing. Caution is advised when using indexing to avoid exceptions, and consideration should be given to code readability versus performance.

Collection Performance: Harnessing AsSpan() for Byte Array Conversion

When working with byte arrays, converting to Span can be achieved through AsSpan(). This method offers performance optimization by providing direct access without creating new arrays, efficient memory management, improved code clarity, and future-proofing for .NET framework evolution. Benchmark results show AsSpan() to be twice as performant with minimal memory allocations.

Collection Performance: Adding Items To a Dictionary

The excerpt from "Rock Your Code" discusses two methods for adding items to a Dictionary in .NET: Add() and TryAdd().

Collection Performance: The Fastest Way To Iterate Over a Collection in .NET!

Discover the quickest method to iterate over a collection in Microsoft.NET with this article, which includes performance benchmark tests.

256 Seconds with dotNetDave: Be careful using ContainsKey() with Dictionary Types

In this episode, I will demonstrate the issues associated with using `ContainsKey()` with Dictionary types in Microsoft .NET, which can potentially lead to performance problems. Updated September 2023.

Collection Performance: Processing Collections with Parallel.For() and Parallel.ForEach()

Since .NET 4.0, under the System.Threading.Tasks namespace, processing of collections can be sped up by using Parallel.For() and Parallel.ForEach(). These methods operate with thread-local data that runs in parallel. Both are easy to use and come with different options. This article shows you how to use these methods along with benchmark results.

Collection Performance: Creating Immutable Sorted Collections

ImmutableSortedDictionary and ImmutableSortedSet are available as immutable sorted collections. Performance benchmarks reveal that ImmutableSortedSet outperforms ImmutableSortedDictionary in both scenarios. Using CreateRange() is more efficient than CreateBuilder() with foreach(). However, employing a List with the Sort() method proves to be the most efficient option.