aaronontheweb/dotnet-skills/csharp-type-design-performance
- community
Checking that the SKILL.md file is still in the repository.
Design .NET types for performance. Seal classes, use readonly structs, prefer static pure functions, avoid premature enumeration, and choose the right collection types.
Install
npx vskill@latest install aaronontheweb/dotnet-skills/csharp-type-design-performanceSKILL.md
Type Design for Performance
When to Use This Skill
Use this skill when:
- Designing new types and APIs
- Reviewing code for performance issues
- Choosing between class, struct, and record
- Working with collections and enumerables
Core Principles
- Seal your types - Unless explicitly designed for inheritance
- Prefer readonly structs - For small, immutable value types
- Prefer static pure functions - Better performance and testability
- Defer enumeration - Don't materialize until you need to
- Return immutable collections - From API boundaries
Seal Classes by Default
Sealing classes enables JIT devirtualization and communicates API intent.
Benefits:
- JIT can devirtualize method calls
- Communicates "this is not an extension point"
- Prevents accidental breaking changes
Readonly Structs for Value Types
Structs should be readonly when immutable. This prevents defensive copies.
When to Use Structs
| Use Struct When | Use Class When | |
|---|---|---|
| Small (≤16 bytes typically) | Larger objects | |
| Short-lived | Long-lived | |
| Frequently allocated | Shared references needed | |
| Value semantics required | Identity semantics required | |
| Immutable | Mutable state |
Prefer Static Pure Functions
Static methods with no side effects are faster and more testable.
Benefits:
- No vtable lookup (faster)
- No hidden state
- Easier to test (pure input → output)
- Thread-safe by design
- Forces explicit dependencies
Don't go overboard - Use instance methods when you genuinely need state or polymorphism.
Defer Enumeration
Don't materialize enumerables until necessary. Avoid excessive LINQ chains.
Async Enumeration
Be careful with async and IEnumerable:
ValueTask vs Task
Use ValueTask for hot paths that often complete synchronously. For real I/O, just use Task.
ValueTask rules:
- Never await a ValueTask more than once
- Never use
.Resultor.GetAwaiter().GetResult()before completion - If in doubt, use Task
Span and Memory for Bytes
Use Span<T> and Memory<T> instead of byte[] for low-level operations.
Common Span Patterns
Collection Return Types
Return Immutable Collections from APIs
Internal Mutation is Fine
Collection Guidelines
| Scenario | Return Type | |
|---|---|---|
| API boundary | IReadOnlyList<T>, IReadOnlyCollection<T> | |
| Static lookup data | FrozenDictionary<K,V>, FrozenSet<T> | |
| Internal building | List<T>, then return as readonly | |
| Single item or none | T? (nullable) | |
| Zero or more, lazy | IEnumerable<T> |
Quick Reference
| Pattern | Benefit | |
|---|---|---|
sealed class | Devirtualization, clear API | |
readonly record struct | No defensive copies, value semantics | |
| Static pure functions | No vtable, testable, thread-safe | |
Defer .ToList() | Single materialization | |
ValueTask for hot paths | Avoid Task allocation | |
Span<T> for bytes | Stack allocation, no copying | |
IReadOnlyList<T> return | Immutable API contract | |
FrozenDictionary | Fastest lookup for static data |
Anti-Patterns
Resources
- Performance Best Practices: https://learn.microsoft.com/en-us/dotnet/standard/performance/
- Span<T> Guidance: https://learn.microsoft.com/en-us/dotnet/standard/memory-and-spans/
- Frozen Collections: https://learn.microsoft.com/en-us/dotnet/api/system.collections.frozen
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/csharp-type-design-performance/SKILL.md
Popularity
- Repository stars
- 768
- Repository forks
- 72
- 7-day trend score
- 33
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 12 Apr 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/aaronontheweb/dotnet-skills/csharp-type-design-performance)