You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Three static collections are populated once and read-many during hot paths. FrozenSet/FrozenDictionary (net8+) give faster lookups than regular HashSet/Dictionary:
TUnit.Core/Discovery/ObjectGraphDiscoverer.cs:52 — SkipTypes (HashSet, 6 entries). Used in ShouldSkipType checks during per-test object-graph traversal.
TUnit.Engine/Discovery/ReflectionTestDataCollector.cs:203 — ExcludedAssemblyNames (HashSet, 20+ entries). Used in Contains(name) per assembly during reflection discovery.
TUnit.Core/Helpers/TupleFactory.cs:10 — TypedFactories (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.
Three static collections are populated once and read-many during hot paths.
FrozenSet/FrozenDictionary(net8+) give faster lookups than regularHashSet/Dictionary:TUnit.Core/Discovery/ObjectGraphDiscoverer.cs:52—SkipTypes(HashSet, 6 entries). Used inShouldSkipTypechecks during per-test object-graph traversal.TUnit.Engine/Discovery/ReflectionTestDataCollector.cs:203—ExcludedAssemblyNames(HashSet, 20+ entries). Used inContains(name)per assembly during reflection discovery.TUnit.Core/Helpers/TupleFactory.cs:10—TypedFactories(Dictionary<Type, Func<object?[], object?>>, 6 entries). Read-only after static ctor finishes;TryGetValuecalled 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/FrozenDictionaryare net8+. TUnit.Core multi-targets netstandard2.0 — guard with#if NET8_0_OR_GREATERand useIReadOnlySet<>/IReadOnlyDictionary<,>field type, or keepHashSet/Dictionaryon netstandard2.0 fallback.