Repository navigation
Reduce JIT by moving code from a generic method into a non-generic one - #1579
Conversation
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.
There was a problem hiding this comment.
🟢 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
ValueTaskstate machines on .NET.
| File | Description |
|---|---|
| src/StreamJsonRpc/JsonRpc.cs | Extracts shared invocation logic while preserving existing behavior. |
Review effort: Balanced
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: 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 |
The
InvokeCoreAsyncmethod 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 usesValueTask<T>and a pool of reusableValueTask<T>objects.