String Performance: String Compression

The content discusses the significance of string compression in programming, outlining four available data formats and demonstrating how to compress and decompress strings using Brotli. It also mentions benchmark results and a tool called Spargine for streamlining the process. For more details, visit the provided link and subscribe for access to exclusive content.

Collection Performance: Iterating Through Reference Value, and Record Types

The author delves into the performance disparities of using reference types, value types, and record types in collections.

General Performance: Constant vs Variable

Using constants for static numerical or string values in code is recommended for clarity and intent. An example demonstrates defining π as a constant or exposing it via a read-only property. Benchmarking shows equal performance. Setting up EditorConfig can help enforce this coding practice, indicating its importance in software development.

Collection Expressions in .NET 8

Beginning with .NET 8, you have the option to employ the novel collection expression to generate frequently used collection values. A collection expression comprises a concise syntax, which, upon evaluation, can be assigned to a wide array of collection types. Key Features of Collection Expressions: Concise Syntax: Easily create collections using square brackets [] and comma-separated elements, such as … Continue reading Collection Expressions in .NET 8

General Performance: Null Coalescing Assignment

C# 8 introduced the null-coalescing assignment operator (??=), allowing for clearer and more concise code. For instance, using "list ??= []" creates a new List() if list is null. Benchmarks indicate that this operator enhances readability and offers a modest performance improvement over traditional null checks.

General Performance: Performance Impact of Sealing Attributes

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: 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.