Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block inlining of IntroSort #89310

Merged
merged 2 commits into from
Jul 21, 2023
Merged

Block inlining of IntroSort #89310

merged 2 commits into from
Jul 21, 2023

Conversation

AndyAyersMS
Copy link
Member

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.

With PGO and (via dotnet#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 dotnet#89106.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 21, 2023
@ghost ghost assigned AndyAyersMS Jul 21, 2023
@ghost
Copy link

ghost commented Jul 21, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: AndyAyersMS
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member Author

@EgorBo @stephentoub PTAL
cc @dotnet/jit-contrib

Benchmark is pretty noisy but this should resolve the regressions we've seen.

Method Job Toolchain Size Mean Error StdDev Median Min Max Ratio RatioSD Allocated Alloc Ratio
Array Job-GINFRD Pre-89106 512 4.969 us 0.5558 us 0.6177 us 4.640 us 4.253 us 6.081 us 1.00 0.00 - NA
Array Job-LXATAE Post-89106 512 5.224 us 0.6870 us 0.7911 us 4.966 us 4.235 us 6.730 us 1.07 0.24 - NA
Array Job-LWDPQF Noinline 512 4.667 us 0.6068 us 0.6745 us 4.440 us 3.856 us 6.299 us 0.96 0.21 - NA

@teo-tsirpanis teo-tsirpanis added area-System.Runtime and removed area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Jul 21, 2023
@ghost
Copy link

ghost commented Jul 21, 2023

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: AndyAyersMS
Assignees: AndyAyersMS
Labels:

area-System.Runtime

Milestone: -

@@ -2207,6 +2207,7 @@ private void IntrospectiveSort(int left, int length)
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include a comment as to why this is here? I imagine the calculus around whether this is valuable could change in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Note IntroSort is nominally doubly recursive but has already had the tail recursive call transformed into a loop manually. If we were ever tempted to undo that and rely on the JIT to do something similar, we might find the NoInline annotation would inhibit that transformation too.

@EgorBo we might consider special heuristics for recursion, generally if the method is large and doesn't have a frequent fast path that avoids recursion, then there's not much to be gained.

@AndyAyersMS AndyAyersMS merged commit f79676c into dotnet:main Jul 21, 2023
@AndyAyersMS
Copy link
Member Author

Perf has returned to "normal"
newplot (71)

Note there is a longer-term regression here from PGO, see #87194.
newplot (72)

@ghost ghost locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Perf] Windows/x64: 1 Regressions in System.Collections.Sort<IntStruct>
4 participants