From 930849e01f0486844d0d0ca0d20ffae82b5ea274 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Mon, 19 Jan 2026 19:13:27 +0200 Subject: [PATCH] Use unoptimized array sort helper on iOS The GenericArraySortHelper<> type was inflated in reflection like fashion which made R2R unable to compile its methods. This means that all methods of this type were interpreted. This commit makes List.Sort() 60x faster. If IsDynamicCodeCompiled is false then the expectation is that we would want to rely as much as possible on r2r code so we want to avoid patterns that are not AOT friendly. This follows the same approach that nativeaot takes in https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.NativeAot.cs. --- .../src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs index 9ccfd2864ee037..30b482d413e94f 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs @@ -23,7 +23,7 @@ private static IArraySortHelper CreateArraySortHelper() { IArraySortHelper defaultArraySortHelper; - if (typeof(IComparable).IsAssignableFrom(typeof(T))) + if (RuntimeFeature.IsDynamicCodeCompiled && typeof(IComparable).IsAssignableFrom(typeof(T))) { defaultArraySortHelper = (IArraySortHelper)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericArraySortHelper), (RuntimeType)typeof(T)); } @@ -56,7 +56,7 @@ private static IArraySortHelper CreateArraySortHelper() { IArraySortHelper defaultArraySortHelper; - if (typeof(IComparable).IsAssignableFrom(typeof(TKey))) + if (RuntimeFeature.IsDynamicCodeCompiled && typeof(IComparable).IsAssignableFrom(typeof(TKey))) { defaultArraySortHelper = (IArraySortHelper)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericArraySortHelper), (RuntimeType)typeof(TKey), (RuntimeType)typeof(TValue)); }