Skip to content

[clrinterp] Split interpreter entry betwen managed and unmanaged callers - #133417

Merged
BrzVlad merged 1 commit into
dotnet:mainfrom
BrzVlad:feature-clrinterp-fast-entry
Sep 15, 2026
Merged

BrzVlad merged 1 commit into
dotnet:mainfrom
BrzVlad:feature-clrinterp-fast-entry

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Sep 8, 2026

Copy link
Copy Markdown
Member

ExecuteIntepretedMethod was carrying quite a bit of logic to handle interpreter entry to an unmanaged callers only. This commit splits the logic into 3 methods:

  • ExecuteInterpretedMethodBody -> creates the interpreter frames then starts executing, acts as a fastpath
  • ExecuteInterpretedMethodFromUnmanagedWorker -> does all the necessary UCO checks/work then calls the above, acts as a slowpath
  • ExecuteInterpretedMethod -> depending on whether the interpreted method is UCO or not, calls the fastpath or the slowpath

We could probably move more code outside the fastpath, for example the async continuation storing, but for now the diff is kept more targeted. Improves interp entry microbenchmark by about 5% on desktop.

ExecuteIntepretedMethod was carrying quite a bit of logic to handle interpreter entry to an unmanaged callers only. This commit splits the logic into 3 methods:
- ExecuteInterpretedMethodBody -> creates the interpreter frames then starts executing, acts as a fastpath
- ExecuteInterpretedMethodFromUnmanagedWorker -> does all the necessary UCO checks/work then calls the above, acts as a slowpath
- ExecuteInterpretedMethod -> depending on whether the interpreted method is UCO or not, calls the fastpath or the slowpath

We could probably move more code outside the fastpath, for example the async continuation storing, for now the change is kept more targeted. Improves interp entry microbenchmark by about 5%.
Copilot AI lite review requested due to automatic review settings September 8, 2026 13:15
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes a sensitive CoreCLR VM interpreter entry/GC-transition path with architecture-specific calling conventions, warranting careful human validation beyond a diff-only review.

Pull request overview

This PR refactors the CoreCLR interpreter entrypoint in prestub.cpp by splitting the interpreter execution logic into separate helper functions, with the goal of reducing overhead on the managed-caller fast path while keeping the unmanaged (UnmanagedCallersOnly) entry checks on a slow path.

Changes:

  • Introduces ExecuteInterpretedMethodBody to encapsulate frame setup, interpreter execution, and async-continuation publication.
  • Introduces ExecuteInterpretedMethodFromUnmanaged to handle reverse-P/Invoke/UCO-specific thread and GC-mode validation plus profiling/debugger transition hooks.
  • Updates ExecuteInterpretedMethod to dispatch to the fast/slow path based on unmanagedCallersOnly.
File summaries
File Description
src/coreclr/vm/prestub.cpp Splits interpreter entry into fast/slow paths to reduce overhead for managed callers while preserving UCO reverse-P/Invoke checks and profiler/debugger hooks.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

@BrzVlad
BrzVlad requested a review from janvorli September 14, 2026 15:09
@janvorli

Copy link
Copy Markdown
Member

@BrzVlad so the perf gain happens just because you've split / refactored the function?

@BrzVlad

BrzVlad commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Yes, there is no change in logic, just that we now consider the managed to managed transition as the common hot path and we remove some checks from it. While this doesn't have significant perf gains as of right now, I believe it is good refactoring to have that could allow us in the future to reduce unnecessary work from this path even more. For example we could remove handling for async methods, or make the stubs call this hot path directly, completely avoiding any checks for UCO. But these are micro optimizations and I don't believe we need to overly commit to them right now.

@BrzVlad

BrzVlad commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

/ba-g unrelated failure

@BrzVlad
BrzVlad merged commit 6b1a445 into dotnet:main Sep 15, 2026
117 of 119 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 16, 2026
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 18, 2026
…ers (dotnet#133417)

ExecuteIntepretedMethod was carrying quite a bit of logic to handle
interpreter entry to an unmanaged callers only. This commit splits the
logic into 3 methods:
- ExecuteInterpretedMethodBody -> creates the interpreter frames then
starts executing, acts as a fastpath
- ExecuteInterpretedMethodFromUnmanagedWorker -> does all the necessary
UCO checks/work then calls the above, acts as a slowpath
- ExecuteInterpretedMethod -> depending on whether the interpreted
method is UCO or not, calls the fastpath or the slowpath

We could probably move more code outside the fastpath, for example the
async continuation storing, but for now the diff is kept more targeted.
Improves interp entry microbenchmark by about 5% on desktop.
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 16, 2026
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.

3 participants