dotnet-perf

Optimize .NET applications by reducing memory allocations with Span<T> and ArrayPool<T>.

Updated Feb 5, 2026
One-click install
npx skills add https://github.com/Objective-Arts/lens --skill dotnet-perf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-perf
Source: https://github.com/Objective-Arts/lens/tree/main/canon/csharp/dotnet-perf
Command: npx skills add https://github.com/Objective-Arts/lens --skill dotnet-perf

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses performance bottlenecks in .NET applications by identifying and eliminating inefficient memory allocations and promoting best practices for high-performance code.

Core Features & Use Cases

  • Allocation Reduction: Guides developers to use Span<T>, ArrayPool<T>, and ObjectPool<T> to minimize heap allocations.
  • Benchmarking: Emphasizes the use of BenchmarkDotNet with MemoryDiagnoser for accurate performance measurement.
  • Use Case: Refactor a critical loop in your C# application that frequently allocates temporary strings or arrays, significantly reducing garbage collection pressure and improving throughput.

Quick Start

Apply the dotnet-perf skill to analyze and optimize the provided C# code for performance.

Frequently Asked Questions about dotnet-perf

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

FAQPage Schema
How do I reduce memory allocations in C# to improve .NET performance?

To reduce memory allocations in C#, utilize `Span<T>` for zero-copy slicing, `ArrayPool<T>` and `ObjectPool<T>` for reusing buffers, and `stackalloc` for stack-based operations to minimize heap pressure and garbage collection overhead.

What is the best way to benchmark .NET memory allocation and code performance?

The best way to benchmark .NET memory allocation is using BenchmarkDotNet with its `MemoryDiagnoser` to accurately measure performance impacts and track allocated bytes during code execution.

When should I use a struct vs a class in C# for high-performance applications?

Use a struct in C# for high-performance applications when you need value type semantics and want to avoid heap allocations; the Skill provides a decision framework for struct vs class selection based on allocation behavior.

How do I optimize string manipulation in .NET to prevent garbage collection pressure?

Optimize string manipulation in .NET by applying best practices for efficient coding patterns, leveraging `Span<T>` for zero-copy operations, and using caching to minimize temporary string allocations in critical loops.

Can I use ref struct and stackalloc for zero-copy operations in .NET?

Yes, you can use `ref struct` and `stackalloc` in .NET to enforce stack-based operations and zero-copy slicing, ensuring that data remains on the stack and avoids costly heap allocations entirely.