Skip to content

Smart Enums Performance

Pawel Gerr edited this page Feb 9, 2026 · 1 revision

FrozenDictionary in .NET 8+

When running on .NET 8 or higher, Smart Enums automatically use FrozenDictionary for internal lookups, providing better performance compared to regular dictionaries.

ReadOnlySpan Support in .NET 9+

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)
    {
        ...
    }
}

Zero-Allocation JSON Deserialization

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.

Clone this wiki locally