Block inlining of IntroSort (#89310)
authorAndy Ayers <andya@microsoft.com>
Fri, 21 Jul 2023 20:06:10 +0000 (13:06 -0700)
committerGitHub <noreply@github.com>
Fri, 21 Jul 2023 20:06:10 +0000 (13:06 -0700)
With PGO and (via #88749) one level of recursive inlining enabled, the jit sees
the recursive call made by `IntroSort` as an attractive inline candidate,
but it isn't.

Fixes #89106.

src/libraries/System.Private.CoreLib/src/System/Array.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs

index 313b064..cecfcf1 100644 (file)
@@ -2207,6 +2207,9 @@ namespace System
                 }
             }
 
+            // IntroSort is recursive; block it from being inlined into itself as
+            // this is currenly not profitable.
+            [MethodImpl(MethodImplOptions.NoInlining)]
             private void IntroSort(int lo, int hi, int depthLimit)
             {
                 Debug.Assert(hi >= lo);
@@ -2421,6 +2424,9 @@ namespace System
                 }
             }
 
+            // IntroSort is recursive; block it from being inlined into itself as
+            // this is currenly not profitable.
+            [MethodImpl(MethodImplOptions.NoInlining)]
             private void IntroSort(int lo, int hi, int depthLimit)
             {
                 Debug.Assert(hi >= lo);
index cf481d8..1d937f4 100644 (file)
@@ -128,6 +128,9 @@ namespace System.Collections.Generic
             }
         }
 
+        // IntroSort is recursive; block it from being inlined into itself as
+        // this is currenly not profitable.
+        [MethodImpl(MethodImplOptions.NoInlining)]
         private static void IntroSort(Span<T> keys, int depthLimit, Comparison<T> comparer)
         {
             Debug.Assert(!keys.IsEmpty);
@@ -402,6 +405,9 @@ namespace System.Collections.Generic
             j = t;
         }
 
+        // IntroSort is recursive; block it from being inlined into itself as
+        // this is currenly not profitable.
+        [MethodImpl(MethodImplOptions.NoInlining)]
         private static void IntroSort(Span<T> keys, int depthLimit)
         {
             Debug.Assert(!keys.IsEmpty);