Agent skill · software engineering · aaronontheweb
type-design-performance
Design .NET types for performance. Seal classes, use readonly structs, prefer static pure functions, avoid premature enumeration, and choose the right collection types.
Why this skill is useful
Provides specific design patterns and performance optimization techniques for .NET types that the AI wouldn't reliably generate on its own.
What it needs
About 5k tokens when loaded. Last updated 2026-07-03. 1,095 stars on the source repository.
What this skill does
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 1. Seal your types - Unless explicitly designed for inheritance 2. Prefer readonly structs - For small, immutable value types 3. Prefer static pure functions - Better performance and testability 4. Defer enumeration - Don't materialize until you need to 5. 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. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills aaronontheweb/csharp-type-design-performance