perf: avoid LINQ chains in TestDependency equality and MethodDataSourceAttribute method matching (original) (raw)

Two equality-style code paths allocate multiple LINQ iterators per comparison:

TUnit.Core/TestDependency.cs:146:

|| !testParams.Select(x => x.Type).SequenceEqual(MethodParameters!))

Select allocates iterator + lambda; SequenceEqual enumerates both. Replace with:

bool typesMatch; if (testParams.Count != MethodParameters!.Length) typesMatch = false; else { typesMatch = true; for (var i = 0; i < testParams.Count; i++) { if (testParams[i].Type != MethodParameters[i]) { typesMatch = false; break; } } }

TUnit.Core/Attributes/TestData/MethodDataSourceAttribute.cs:185:

&& x.GetParameters().Select(p => p.ParameterType).SequenceEqual(Arguments.Select(a => a?.GetType())))

Two Selects + a SequenceEqual — three iterators per candidate method during data source resolution. Same loop refactor applies.

Why hot:

TFM: No gating.