Skip to content

Reduce JIT by moving code from a generic method into a non-generic one - #1579

Merged
Andrew Arnott (AArnott) merged 1 commit into
mainfrom
jit-fix
Oct 20, 2026
Merged

Andrew Arnott (AArnott) merged 1 commit into
mainfrom
jit-fix

Conversation

@AArnott

Copy link
Copy Markdown
Member

The InvokeCoreAsync method was large and generic, yet it only needed the generic context for one statement. By moving the bulk of the method into a new, non-generic private method, the JIT only compiles it once. Generic type arguments that are value types now only JIT a very small thunk method.

To avoid allocating an extra Task<T> and state machine (on .NET), the private method uses ValueTask<T> and a pool of reusable ValueTask<T> objects.

The `InvokeCoreAsync` method was large and generic, yet it only needed the generic context for one statement. By moving the bulk of the method into a new, non-generic private method, the JIT only compiles it once. Generic type arguments that are value types now only JIT a very small thunk method.

To avoid allocating an extra `Task<T>` and state machine (on .NET), the private method uses `ValueTask<T>` and a pool of reusable `ValueTask<T>` objects.
Comment thread src/StreamJsonRpc/JsonRpc.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused refactor preserves invocation behavior and awaits the pooled ValueTask exactly once.

No open issues 🎉

What changed in this PR

Reduces repeated JIT compilation by moving shared RPC invocation logic out of the generic method.

Changes:

  • Keeps generic result conversion in a small wrapper.
  • Extracts request handling into a non-generic helper using pooled ValueTask state machines on .NET.
File Description
src/​StreamJsonRpc/​JsonRpc.cs Extracts shared invocation logic while preserving existing behavior.

Review effort: Balanced

Copilot AI commented Oct 19, 2026

Copy link
Copy Markdown

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Authenticate to Azure with GitHub OIDC

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

@AArnott
Andrew Arnott (AArnott) merged commit 30cdea5 into main Oct 20, 2026
9 of 10 checks passed
@AArnott
Andrew Arnott (AArnott) deleted the jit-fix branch October 20, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants