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

JIT differences in reporting call sites in GC info #103917

Closed
jakobbotsch opened this issue Jun 24, 2024 · 6 comments · Fixed by #103950
Closed

JIT differences in reporting call sites in GC info #103917

jakobbotsch opened this issue Jun 24, 2024 · 6 comments · Fixed by #103950
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@jakobbotsch
Copy link
Member

jakobbotsch commented Jun 24, 2024

The JIT has an optimization for MinOpts compilations where we do not bother reporting call sites at all:

if (noTrackedGCSlots && regMask == 0)
{
// No live GC refs in regs at the call -> don't record the call.
}

This optimization is conditioned on noTrackedGCSlots:

const bool noTrackedGCSlots =
(compiler->opts.MinOpts() && !compiler->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT) &&
!JitConfig.JitMinOptsTrackGCrefs());

Note that JitMinOptsTrackGCrefs is 0 for xarch but 1 everywhere else, so the optimization only kicks in for xarch:

#if defined(TARGET_AMD64) || defined(TARGET_X86)
#define JitMinOptsTrackGCrefs_Default 0 // Not tracking GC refs in MinOpts is new behavior
#else
#define JitMinOptsTrackGCrefs_Default 1
#endif
RELEASE_CONFIG_INTEGER(JitMinOptsTrackGCrefs, W("JitMinOptsTrackGCrefs"), JitMinOptsTrackGCrefs_Default)

From my measurements the optimization saves around 23% on GC info size reported by MinOpts contexts. As a downside it does not allow for the suspension on return addresses that @VSadov implemented recently. We should decide whether we want to enable it generally or not.

@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 Jun 24, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jun 24, 2024
Copy link
Contributor

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

@jkotas
Copy link
Member

jkotas commented Jun 24, 2024

This change came from https://github.com/dotnet/coreclr/pull/9869/files#diff-081cd7404db539556560f8746ba2f1928ec14424fd64192aba02316bedac4183R219 . I do not see a reason for having platform differences in GC encoding like this one. I think we should enable the x64 path everywhere.

I think it is fine to have worse GC suspension behavior with minopts. Minops means suboptimal performance, and GC suspension tail latency is part of the bundle.

the optimization saves around 23% on GC info size reported by MinOpts contexts.

The primary motivation for the original change was JIT throughput improvement. The GC info size reduction was nice side-effect.

@VSadov
Copy link
Member

VSadov commented Jun 24, 2024

Also, it is the highly optimized code with tight loops and tiny calls that benefits from more interruption points. MinOpts will likely still be fine.

@jakobbotsch
Copy link
Member Author

The primary motivation for the original change was JIT throughput improvement. The GC info size reduction was nice side-effect.

I imagine the main throughput win within the JIT came from avoiding computing liveness for the GC pointers, and as a consequence this required that we reported all GC pointers as untracked (resulting in the size win). That part is enabled everywhere even today (by virtue of liveness analysis not running in MinOpts).

The size optimization here is somewhat separate: it is realizing that if a call site has no interesting GC information associated with it, then we can avoid describing at all in the GC info that any call site exists there. Once we stopped tracking GC-typed locals I suppose this became true in MinOpts, but I think this size optimization would have been equally applicable in optimized code that ended up without any interesting GC information at a specific call site before @VSadov's recent work.

jakobbotsch added a commit to jakobbotsch/runtime that referenced this issue Jun 25, 2024
When the call-sites have no interesting GC information we avoid
reporting them, but this behavior was enabled only for x86/x64. Enable
this on other platforms too.

Fix dotnet#103917
@VSadov
Copy link
Member

VSadov commented Jun 25, 2024

I think this size optimization would have been equally applicable in optimized code that ended up without any interesting GC information at a specific call site before @VSadov's recent work

I think this is correct. We have some code that relies on presence of call sites/safepoints (like extra interruptibility points, asserts) or on enumerating all safepoints in GC info (like GC stress), but those are all basically reliability enhancements and not required to just make code run.

There should be a lot more opportunities for this optimization in MinOpts, so we could not pass by and enabled it.
For optimized code, I'd expect the opportunity will be limited, so perhaps it is not worth it, considering that "uninteresting" safepoints are still useful, even if not strictly required.

If it is easy to measure, I wonder what would be impact if this is enabled in optimized code. At least as a data point.

@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Jun 26, 2024
@JulieLeeMSFT JulieLeeMSFT added this to the 9.0.0 milestone Jun 26, 2024
@jakobbotsch
Copy link
Member Author

I'll move this to 10. Don't see a good reason to churn it this late.

@jakobbotsch jakobbotsch modified the milestones: 9.0.0, 10.0.0 Aug 1, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Oct 28, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants