dotnet-performance-patterns

Optimize .NET 8.0+ applications using Span<T>, Memory<T>, and ArrayPool<T>.

71|10|Updated Feb 11, 2026
One-click install
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-performance-patterns-wshaddix
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-performance-patterns
Source: https://github.com/wshaddix/dotnet-skills/tree/main/skills/dotnet-performance-patterns
Command: npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-performance-patterns-wshaddix

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses performance bottlenecks in .NET applications by providing guidance on optimizing memory allocations, improving throughput, and reducing CPU usage.

Core Features & Use Cases

  • Zero-Allocation Techniques: Learn to use Span<T>, Memory<T>, and ArrayPool<T> to minimize garbage collection pressure.
  • Struct and Class Optimization: Understand the performance implications of readonly struct, ref struct, and sealed classes.
  • Stack Allocation: Utilize stackalloc for efficient, small, stack-based memory allocations.
  • String Performance: Optimize string comparisons and building for better performance.
  • Use Case: Refactor a high-throughput data parsing method to eliminate unnecessary string allocations, significantly reducing GC pauses and improving overall application responsiveness.

Quick Start

Apply Span<T> to a string parsing method to eliminate allocations.

Frequently Asked Questions about dotnet-performance-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce garbage collection pressure in .NET applications?

Reduce garbage collection pressure in .NET by applying zero-allocation techniques using Span<T>, Memory<T>, and ArrayPool<T> to minimize heap allocations and improve throughput.

What is the performance difference between readonly struct and ref struct in .NET?

readonly struct prevents defensive copies during method calls, while ref struct restricts a type to the stack, enabling safe, high-performance memory processing without heap allocation overhead.

How do I use stackalloc for efficient memory allocation in C#?

Use stackalloc for small, stack-based memory allocations to bypass the managed heap, reducing garbage collection overhead while ensuring safe memory management in high-throughput .NET scenarios.

Can I optimize string parsing in .NET 8.0 without creating allocations?

Optimize string parsing in .NET 8.0 without allocations by applying Span<T> to process string data directly, eliminating unnecessary string object creation and reducing GC pauses.

Why use sealed classes for .NET performance optimization?

Sealed classes optimize .NET performance by preventing further inheritance, enabling the runtime to use devirtualization and inline method calls more aggressively, reducing CPU execution overhead.

Does ArrayPool<T> work well for high-throughput data parsing in .NET?

ArrayPool<T> works well for high-throughput data parsing in .NET by reusing array buffers instead of allocating new ones, significantly minimizing memory traffic and garbage collection pauses.