type-design-performance

Optimize .NET type design to reduce memory allocations and improve JIT optimization.

Updated Feb 15, 2026
One-click install
npx skills add https://github.com/Buggz/Thuddle --skill type-design-performance-buggz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-design-performance
Source: https://github.com/Buggz/Thuddle/tree/main/.claude/skills/csharp-type-design-performance
Command: npx skills add https://github.com/Buggz/Thuddle --skill type-design-performance-buggz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more performant .NET code by guiding them on how to design types effectively, reducing memory allocations and improving execution speed.

Core Features & Use Cases

  • Type Sealing: Learn when and why to seal classes.
  • Struct vs. Class: Understand the performance implications of choosing structs (especially readonly record struct) over classes.
  • Function Design: Prefer static pure functions for better performance and testability.
  • Collection Handling: Optimize how and when collections are materialized and returned.
  • Async Patterns: Use ValueTask appropriately and handle async enumeration efficiently.
  • Memory Management: Leverage Span<T> and Memory<T> for efficient byte manipulation.
  • Use Case: When designing a new high-throughput API in C#, use this skill to ensure that the data structures and methods chosen minimize overhead and maximize performance.

Quick Start

Apply the type-design-performance skill to review the C# code for potential performance bottlenecks in type design.

Frequently Asked Questions about type-design-performance

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

FAQPage Schema
How do I optimize .NET type design for performance and reduce memory allocations?

Optimize .NET type design by sealing classes, using readonly structs, and preferring static pure functions to reduce memory allocations and improve execution speed. This approach minimizes overhead and enhances JIT optimization.

When should I use a readonly struct instead of a class in C#?

Use a readonly struct instead of a class in C# when you need value type semantics and want to avoid heap allocations. Readonly structs prevent defensive copies, improving execution speed and reducing memory overhead.

What is the best way to handle collections in high-throughput C# APIs?

The best way to handle collections in high-throughput C# APIs is deferring enumeration and choosing appropriate collection types. This minimizes premature materialization, reducing memory allocations and improving overall throughput.

How does sealing classes improve .NET performance?

Sealing classes improves .NET performance by enabling the JIT compiler to apply more aggressive optimizations, such as devirtualizing method calls. This reduces dispatch overhead and increases execution speed.

Can I use Span<T> and Memory<T> for efficient byte manipulation in .NET?

Yes, you can use Span<T> and Memory<T> for efficient byte manipulation in .NET. These types provide safe, managed access to contiguous memory regions without allocating new arrays on the heap.

When should I use ValueTask instead of Task for async patterns in C#?

Use ValueTask instead of Task in C# when your async method often completes synchronously. This avoids allocating a Task object, reducing memory overhead and improving performance in high-throughput scenarios.