# dotnet-performance-patterns

dotnet-performance-patterns is a Claude Code skill for .NET 8+ architecture patterns that reduce allocations using Span, Memory, and ArrayPool.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 122 installs · ★ 92 repo stars
- Author: wshaddix
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/wshaddix/dotnet-skills/tree/HEAD/skills/dotnet-performance-patterns/SKILL.md
- Updated: 2026-02-27
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/dotnet-performance-patterns

## What it does

This skill focuses on memory throughput and allocation reduction in modern .NET 8+ applications. It emphasizes the rationale behind low-level optimizations: slice-based parsing with `ReadOnlySpan<char>`, handling memory across asynchronous boundaries via `Memory<T>`, and renting large byte arrays with `ArrayPool<T>.Shared` to avoid Large Object Heap fragmentation.

The instructions break down typical pooling pitfalls, such as relying on `buffer.Length` instead of the actual slice size or omitting `clearArray: true` on sensitive payloads. Value type design is another core topic: declaring a `readonly struct` stops the JIT from creating defensive copies under `in` parameters, while `ref struct` ensures data never escapes to the managed heap.

The guidance assumes a .NET 8.0 runtime baseline, meaning older framework targets cannot run several of the highlighted APIs.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-performance-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/dotnet-performance-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/dotnet-performance-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-performance-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/dotnet-performance-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-performance-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/dotnet-performance-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install wshaddix/dotnet-skills skills/dotnet-performance-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/dotnet-performance-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-performance-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/wshaddix/dotnet-skills --path skills/dotnet-performance-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/dotnet-performance-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-performance-patterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/wshaddix/dotnet-skills/tree/HEAD/skills/dotnet-performance-patterns/SKILL.md

## When to use it
- eliminate GC pressure during string parsing by slicing with `ReadOnlySpan<char>`
- avoid Large Object Heap allocations using rented buffers from `ArrayPool<byte>`
- prevent JIT defensive copying of structs passed with the `in` parameter
- pass memory slices into asynchronous stream readers using `Memory<byte>`

## Example prompts
- Refactor our log parsing function to use `ReadOnlySpan<char>` without allocating substrings.
- Show how to read a large stream using `ArrayPool<byte>.Shared` with proper cleanup in a finally block.
- Optimize this struct to prevent defensive copies when passed via `in` parameter.

## Similar
- [analyzing-dotnet-performance](https://affpapa.org/en/nevibecode/skills/analyzing-dotnet-performance.md) — skill · 6200 installs
- [dotnet-inspect-performance](https://affpapa.org/en/nevibecode/skills/dotnet-inspect-performance.md) — skill · 411 installs
- [dotnet-backend-patterns](https://affpapa.org/en/nevibecode/skills/dotnet-backend-patterns.md) — skill · 19076 installs
- [dotnet-patterns](https://affpapa.org/en/nevibecode/skills/dotnet-patterns.md) — skill · 6300 installs
- [type-design-performance](https://affpapa.org/en/nevibecode/skills/type-design-performance.md) — skill · 698 installs
- [eval-performance](https://affpapa.org/en/nevibecode/skills/eval-performance.md) — skill · 4500 installs

From the same set: [wshaddix/dotnet-skills](https://affpapa.org/en/nevibecode/by/wshaddix/dotnet-skills.md) — 24 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
