-
Notifications
You must be signed in to change notification settings - Fork 5
Smart Enums Performance
Pawel Gerr edited this page Feb 9, 2026
·
1 revision
When running on .NET 8 or higher, Smart Enums automatically use FrozenDictionary for internal lookups, providing better performance compared to regular dictionaries.
String-based Smart Enums in .NET 9+ support ReadOnlySpan<char> operations for improved performance:
[SmartEnum<string>]
public partial class ProductType
{
public static readonly ProductType Electronics = new("Electronics");
// In .NET 9+, you can use ReadOnlySpan<char> for lookups - no string allocation needed
public static bool TryGet(ReadOnlySpan<char> key, out ProductType? item)
{
...
}
}ReadOnlySpan<char> support also enables zero-allocation JSON deserialization with System.Text.Json on .NET 9+. See Zero-Allocation JSON Deserialization for details on how this works and configuration options.
- Home
- Smart Enums
- Value Objects
- Discriminated Unions
- Object Factories
- Analyzer Diagnostics
- Source Generator Configuration
- Convenience methods and classes
- Migrations
- Version 7
- Version 8