Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

perf: convert read-only static HashSet/Dictionary to FrozenSet/FrozenDictionary #6047

Copy link
Copy link

Description

@thomhurst
Issue body actions

Three static collections are populated once and read-many during hot paths. FrozenSet/FrozenDictionary (net8+) give faster lookups than regular HashSet/Dictionary:

  1. TUnit.Core/Discovery/ObjectGraphDiscoverer.cs:52SkipTypes (HashSet, 6 entries). Used in ShouldSkipType checks during per-test object-graph traversal.

    private static readonly HashSet<Type> SkipTypes = [typeof(string), typeof(decimal), ...];
  2. TUnit.Engine/Discovery/ReflectionTestDataCollector.cs:203ExcludedAssemblyNames (HashSet, 20+ entries). Used in Contains(name) per assembly during reflection discovery.

  3. TUnit.Core/Helpers/TupleFactory.cs:10TypedFactories (Dictionary<Type, Func<object?[], object?>>, 6 entries). Read-only after static ctor finishes; TryGetValue called per tuple-arg conversion.

Fix: declare as FrozenSet<T> / FrozenDictionary<K,V> and initialize via .ToFrozenSet() / .ToFrozenDictionary() at the end of the static initializer.

Why hot: All three are queried inside per-test or per-assembly loops.
TFM: FrozenSet/FrozenDictionary are net8+. TUnit.Core multi-targets netstandard2.0 — guard with #if NET8_0_OR_GREATER and use IReadOnlySet<>/IReadOnlyDictionary<,> field type, or keep HashSet/Dictionary on netstandard2.0 fallback.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestNew feature or requestperformancePerformance optimizationPerformance optimization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.