Skip to content

Analyzer: Introduce an analyzer to recommend optimize dictionaries with small key types #85489

@geeknoid

Description

@geeknoid

Introduce an analyzer that recommends replacing dictionaries where a key is a byte, sbyte, enum with simple arrays instead.

It's amazing what creeps into code bases over time. Dictionaries that have a byte or enum key show up once in a while and can generally be much more efficiently implemented with arrays. Flagging this is happening can help developers make better choices.

The simplest form of analysis just looks for dictionaries having those simple key types. You can get fancier and try to discover other opportunities for optimization. For example, if you can prove that a dictionary which has an int key only ever contains smaller keys, the analyzer could recommend switching to arrays too. For example, this might be possible around sequences that initialize frozen dictionaries.

The analyzer we have for this looks for uses of constructors of relevant collections and just flags those, as opposed to flagging every use of Dictionary<byte, xxx> in a code base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Collectionscode-analyzerMarks an issue that suggests a Roslyn analyzerpartner-impactThis issue impacts a partner who needs to be kept updated

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions