type-design-performance

Optimize .NET type design for performance using sealing, readonly structs, and collection choices.

Updated Dec 4, 2022
One-click install
npx skills add https://github.com/devingoble/CloudOStat --skill type-design-performance-devingoble
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-design-performance
Source: https://github.com/devingoble/CloudOStat/tree/main/.github/skills/csharp-type-design-performance
Command: npx skills add https://github.com/devingoble/CloudOStat --skill type-design-performance-devingoble

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 Design Principles: Learn best practices for choosing between structs and classes, using readonly, and applying sealed.
  • Performance Optimization: Understand how to defer enumeration, use ValueTask appropriately, and leverage Span<T> for efficient memory handling.
  • Use Case: When designing a new data model for a high-throughput API, use this Skill to ensure your types minimize overhead and maximize performance.

Quick Start

Apply the type-design-performance skill to review the C# code provided for potential performance improvements 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 better performance?

To optimize .NET type design for enhanced performance, you should seal classes, use readonly structs, prefer static pure functions, defer enumeration, and select appropriate collection types to reduce memory allocations and maximize execution speed.

What is the difference between structs and classes for C# performance optimization?

In C# performance optimization, using readonly structs reduces memory allocation overhead, while sealing classes prevents virtual method dispatch costs, ensuring efficient memory management and faster execution.

How do I design a high-throughput API data model in C#?

Designing a high-throughput API data model in C# requires applying type design principles like using ValueTask appropriately, leveraging Span<T> for efficient memory handling, and choosing appropriate collection types to minimize overhead.

When should I use ValueTask and Span<T> for .NET memory management?

You should use ValueTask and Span<T> for .NET memory management when building performance-critical applications, as they enable efficient memory handling and reduce allocations by deferring enumeration and operating on contiguous memory regions.

Can I use this type design optimization approach for existing C# code reviews?

Yes, you can use this type design optimization approach for existing C# code reviews by applying the skill to review provided C# code, identifying potential performance improvements, and ensuring best practices for efficient memory management.