dotnet/roslyn

Favor `Kind` check over type checking when appropriate

Open

#69,048 opened on Jul 15, 2023

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-CompilersArea-Performancehelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

image

Type checking here is 2.8% of CPU time. A good portion of it happens for symbols.

Would the following be more efficient?

if (symbol.Kind == SymbolKind.KindWeLookFor)
{
    return Unsafe.As<SymbolTypeToCastTo>(symbol);
}

Contributor guide