perf: avoid closure allocation in AfterHookPairTracker GetOrAdd (original) (raw)
TUnit.Engine/Services/AfterHookPairTracker.cs:158:
var task = _afterAssemblyTasks.GetOrAdd(assembly, a => taskFactory(a).AsTask());
The lambda captures taskFactory, allocating a closure per call (including cache hits).
Fix: TryGetValue fast-path first, only call GetOrAdd on miss. Same pattern as BeforeHookTaskCache.GetOrCreateBeforeClassTask.
Why hot: Per assembly teardown, but closure alloc is per-call.
TFM: No gating.
Related: companion to the BeforeHookTaskCache issue.