type-design-performance

Guide .NET type design for performance with struct versus class decisions.

10|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/AGIBuild/Agibuild.Fulora --skill type-design-performance-agibuild
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-design-performance
Source: https://github.com/AGIBuild/Agibuild.Fulora/tree/main/.cursor/skills/csharp-type-design-performance
Command: npx skills add https://github.com/AGIBuild/Agibuild.Fulora --skill type-design-performance-agibuild

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers make informed decisions about designing .NET types to maximize performance, reduce memory allocations, and improve API efficiency.

Core Features & Use Cases

  • Struct vs. Class Decisions: Provides a matrix and guidelines for choosing the right type category.
  • Immutability Patterns: Emphasizes readonly struct and record types for predictable behavior.
  • Collection Optimization: Guides selection of efficient collection types like FrozenDictionary and proper enumeration strategies.
  • Use Case: When designing a new data transfer object (DTO) or a performance-critical utility class, use this Skill to ensure you're choosing the most efficient type (e.g., record struct vs. record class, Span<T> vs. Memory<T>).

Quick Start

Use the type-design-performance skill to decide whether to use a struct or class for a new data type.

Frequently Asked Questions about type-design-performance

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

FAQPage Schema
When should I use a struct vs a class in .NET for performance?

Use a struct vs class decision matrix in .NET to evaluate size, immutability, and allocation behavior. Favor readonly structs to reduce memory allocations and improve speed in performance-critical scenarios.

How do I optimize .NET collections for better performance?

Optimize .NET collections by selecting efficient types like FrozenDictionary and deferring enumeration. This skill guides proper collection usage and enumeration strategies to minimize processing overhead.

What is the best way to design an immutable data transfer object in .NET?

Design an immutable DTO in .NET using readonly struct or record types. This skill emphasizes these patterns to ensure predictable behavior and maximize API efficiency.

Should I seal .NET types by default for performance?

Sealing .NET types by default is an enforced principle in this skill. Sealing types prevents inheritance overhead, enabling the runtime to optimize method calls and improve execution speed.

Can I use Span<T> instead of Memory<T> for .NET performance tuning?

Use Span<T> instead of Memory<T> for .NET performance tuning when handling synchronous, stack-based memory operations. This skill helps choose the most efficient type for your specific data processing context.

What are the limitations of using structs in .NET type design?

Limitations of using structs in .NET type design include boxing overhead with non-generic APIs and potential copying costs for large structures. This skill guides when to avoid structs and defer enumeration to mitigate these constraints.