Skip to content

perf: pool HashSet<WaitingTest> in WaitingTestIndex.GetCandidatesForReleasedKeys #6054

Description

@thomhurst

TUnit.Engine/Scheduling/WaitingTestIndex.cs:85:

public HashSet<WaitingTest> GetCandidatesForReleasedKeys(IReadOnlyList<string> releasedKeys)
{
    var candidates = new HashSet<WaitingTest>();
    // ... fills via UnionWith ...
    return candidates;
}

A fresh HashSet<WaitingTest> is allocated on every constraint-key release. Caller iterates the set then discards it.

Options:

  • Pool via the existing TUnit.Engine/Services/TestExecution/HashSetPool.cs pattern (returns pooled HashSet<T> rented from ConcurrentBag<object>).
  • Or inline the union into the caller's enumeration so no intermediate set is needed (deduplication via a single HashSet reused across calls, cleared with .Clear() before each use).

Why hot: Runs every time a constraint key is released, scaling with constrained-test count in ConstraintKeyScheduler.cs.
TFM: No gating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions