-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Improve startup perf by avoiding JIT when invoking well-known signatures #115345
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tagging subscribers to this area: @dotnet/area-system-reflection |
AustinWise
reviewed
May 7, 2025
src/coreclr/System.Private.CoreLib/src/System/Reflection/MethodInvokerCommon.CoreCLR.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
May 7, 2025
src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs
Show resolved
Hide resolved
This was referenced May 7, 2025
… to use interpreted mode on first call to each method
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the main contribution for tracking issue #112994.
For a R2R-enabled console "hello world" app, it reduced the jitted methods during startup by half (24 to 12) saving ~9% or 7ms (locally from 78->71ms).
For a non-R2R app there will be no jit necessary for each well-known signature after the first is jitted since they are cached. They are cacheable since the IL uses calli with no coupling to specific MemberInfo tokens. Note that it is possible to add calli and caching to the emit-based path (non-well-known cases) as was done in the prior PR for this; that would allow similar perf benefits of avoiding jit (+emit) for signatures that have already done that, but also adds the complexity and overhead of a cache that needs to key on each parameter.
Currently, the well-known method list is currently fairly short but will still cover many signatures because:
Design \ implementation notes:
InvokerEmitUtil.cs
for a total of 5. This also pushed the code to add more shared methods in that file.IntPtr.Zero
for the other cases, this avoids having additional delegates and conditionals to call a different delegate.ForceInterpretedInvoke
is set. This code should be removed shortly. Previously, the interpreted path is used for the first call to each method, then the method is emit'd on the second call but since we have the intrinsics now for startup\warmup, we should no longer have to do this. This also simplified the code since we no longer need to switch dynamically, and we moved from 3 fields to hold the 3 delegates to 1 field with appropriate casts to one of the 5 delegates._allocator
field.