type-design-performance

Guide .NET type design for performance with sealing, readonly structs, and static pure functions.

Updated May 31, 2026
One-click install
npx skills add https://github.com/nicolashuber/opencode-config --skill type-design-performance-nicolashuber
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-design-performance
Source: https://github.com/nicolashuber/opencode-config/tree/main/skills/csharp-type-design-performance
Command: npx skills add https://github.com/nicolashuber/opencode-config --skill type-design-performance-nicolashuber

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill unit helps developers design .NET types for performance, addressing common pitfalls like premature enumeration and wrong collection types.

Core Features & Use Cases

  • Type Sealing: Improve JIT performance and API stability by sealing classes appropriately.
  • Readonly Structs: Utilize readonly structs for small, immutable value types to avoid defensive copies.
  • Static Pure Functions: Enhance performance and testability with static pure functions.
  • Defer Enumeration: Avoid unnecessary materialization of enumerables until necessary.
  • ValueTask vs Task: Optimize hot paths with ValueTask to reduce allocation overhead.

Quick Start

Analyze your .NET type design with the 'type-design-performance' skill to identify areas for performance improvement.

Frequently Asked Questions about type-design-performance

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

FAQPage Schema
How do I improve .NET performance through type design?

Optimize .NET performance by sealing classes, using readonly structs for immutable values, and applying static pure functions. This approach enhances JIT compilation efficiency and reduces unnecessary allocations in your application.

Why does using readonly structs improve C# application performance?

Readonly structs improve C# performance by preventing defensive copies. Using them for small, immutable value types avoids hidden struct copies during method calls, directly reducing memory overhead.

When should I use ValueTask instead of Task in C# to optimize hot paths?

Use ValueTask instead of Task in C# hot paths to reduce allocation overhead. ValueTask is ideal for asynchronous operations that frequently complete synchronously, avoiding heap allocations and improving performance tuning in critical code sections.

What is premature enumeration in .NET and how do I avoid it?

Premature enumeration in .NET is the unnecessary materialization of enumerables before needed. Avoid it by deferring enumeration until absolutely necessary, which preserves performance tuning by preventing redundant memory allocations and multiple iterations.

Does sealing classes in C# really help with JIT compilation performance?

Sealing classes in C# helps JIT compilation performance by allowing the compiler to optimize method calls. Sealed types enable devirtualization, which removes virtual method table lookups and improves API stability and execution speed.

What do I need to know about the .NET type system to optimize type design?

Optimizing type design requires understanding the .NET type system and JIT compilation. You need familiarity with value versus reference types, struct behavior, and asynchronous programming patterns to effectively apply performance tuning techniques.