From c854da7211b5539d83788ec140c3c8fd2dd59628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 31 May 2026 16:19:40 +0200 Subject: [PATCH] perf: convert InternalOnlyExtensions from array property to static readonly HashSet Each call to ServiceProvider.GetServicesInternal with skipInternalOnlyExtensions=true previously allocated a new Type[] (5 elements) and used IEnumerable.Contains for an O(n) lookup. By switching to a static readonly HashSet, the set is allocated once at class initialization and Contains() is O(1). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Microsoft.Testing.Platform/Services/ServiceProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Services/ServiceProvider.cs b/src/Platform/Microsoft.Testing.Platform/Services/ServiceProvider.cs index 7b41dda061..fa54abff58 100644 --- a/src/Platform/Microsoft.Testing.Platform/Services/ServiceProvider.cs +++ b/src/Platform/Microsoft.Testing.Platform/Services/ServiceProvider.cs @@ -19,7 +19,7 @@ internal sealed class ServiceProvider : IServiceProvider, ICloneable public bool AllowTestAdapterFrameworkRegistration { get; set; } #pragma warning disable CS0618 // Type or member is obsolete - private static Type[] InternalOnlyExtensions => + private static readonly HashSet InternalOnlyExtensions = [ // TestHost typeof(ITestHostApplicationLifetime),