Skip to content

Block inlining of IntroSort - #89310

Merged
AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:Fix89106
Jul 21, 2023
Merged

Block inlining of IntroSort#89310
AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:Fix89106

Conversation

@AndyAyersMS

Copy link
Copy Markdown
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.
Fixesdotnet#89106.
@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 21, 2023
@ghost

Copy link
Copy Markdown

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
Copy Markdown
MemberAuthor

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

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

MethodJobToolchainSizeMeanErrorStdDevMedianMinMaxRatioRatioSDAllocatedAlloc Ratio
ArrayJob-GINFRDPre-891065124.969 us0.5558 us0.6177 us4.640 us4.253 us6.081 us1.000.00-NA
ArrayJob-LXATAEPost-891065125.224 us0.6870 us0.7911 us4.966 us4.235 us6.730 us1.070.24-NA
ArrayJob-LWDPQFNoinline5124.667 us0.6068 us0.6745 us4.440 us3.856 us6.299 us0.960.21-NA

@teo-tsirpanisteo-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
Copy Markdown

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:-

}
}

[MethodImpl(MethodImplOptions.NoInlining)]

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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:mainJul 21, 2023
@AndyAyersMS

Copy link
Copy Markdown
MemberAuthor

Perf has returned to "normal"
newplot (71)

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

@ghostghost locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for freeto 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

@AndyAyersMS@EgorBo@stephentoub@teo-tsirpanis