perf(engine): hoist GetParameters and dict-dedup AfterTestDiscovery hooks by thomhurst · Pull Request #6062 · thomhurst/TUnit (original) (raw)
…via dict
Move method.GetParameters() out of the closures in CreateInstanceHookDelegate and CreateHookDelegate so each hook delegate calls reflection once at factory creation instead of every invocation. Eliminates a per-hook-call ParameterInfo[] allocation across all Before/After hooks in reflection mode.
Replace the Sources.AfterTestDiscoveryHooks.Any(...) linear scan + per-element LazyHookEntry.Materialize() with a ConcurrentDictionary<(string, Type), bool> TryAdd, matching the existing _registeredMethods pattern. Defense-in-depth dedup is now O(1) and does not force lazy materialization just to compare.