type-design-performance

Apply .NET type design rules to reduce allocations and improve runtime performance.

Updated Mar 3, 2026
One-click install
npx skills add https://github.com/Thorstensen/claude-template --skill type-design-performance-thorstensen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-design-performance
Source: https://github.com/Thorstensen/claude-template/tree/main/.claude/skills/csharp-type-design-performance
Command: npx skills add https://github.com/Thorstensen/claude-template --skill type-design-performance-thorstensen

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps teams reduce performance pitfalls caused by non-sealed types, mutable state, and improper collection choices.

Core Features & Use Cases

  • Sealing classes by default to enable JIT devirtualization and communicate API intent.
  • Prefer readonly structs for immutable value types to avoid defensive copies.
  • Favor static pure functions for better testability and predictable performance.
  • Defer enumeration and return immutable collections at API boundaries.
  • Use case: when designing a high-throughput API or reviewing performance hotspots in existing code.

Quick Start

Apply these guidelines when starting a new API design: seal non-inheritance types, use readonly structs for immutable value types, implement static pure functions, defer enumeration, and return immutable collections.

Frequently Asked Questions about type-design-performance

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

FAQPage Schema
How do I design high-performance .NET types to minimize allocations?

Design high-performance .NET types by sealing non-inheritance classes, adopting readonly structs, implementing static pure functions, and returning immutable collections to minimize runtime allocations.

Why should I seal classes by default in .NET API design?

Sealing classes by default enables JIT devirtualization and clearly communicates API intent, which improves runtime performance and prevents unintended inheritance in high-throughput .NET APIs.

When should I use readonly structs over regular structs in .NET?

Use readonly structs for immutable value types to avoid defensive copies and ensure predictable performance when designing high-performance .NET APIs.

What is the best way to handle enumeration at API boundaries in .NET?

Defer enumeration and return immutable collections at API boundaries to maximize performance and prevent unexpected mutations when designing high-throughput .NET APIs.

How do I choose between class, struct, and record for performance hotspots?

Choose between class, struct, and record by evaluating allocation requirements and mutability, preferring sealed classes and readonly structs to optimize performance hotspots in .NET.