perf(generator): return the request task instead of awaiting it - #2302
Merged
Conversation
- Emit the reflection fallback path without async/await so a generated method hands back the request builder's task. Awaiting allocated a second state machine per call whose only job was to re-wrap that task. - Drop the async and configure-await plumbing from the method-opening and return-statement emitters, which is now constant either way. - Pin the fallback emission shape with a test; it had no coverage.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2302 +/- ##
==========================================
- Coverage 99.91% 99.91% -0.01%
==========================================
Files 192 192
Lines 10031 10029 -2
Branches 1925 1924 -1
==========================================
- Hits 10022 10020 -2
Partials 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisPulman
approved these changes
Aug 13, 2026
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
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.



What kind of change does this PR introduce?
Performance optimisation in the source generator.
What is the new behavior?
No generated Refit method carries an async state machine; every method hands its task straight back to the caller.
return (Task<T>)refitFunc(this.Client, args);rather thanreturn await ((Task<T>)refitFunc(...)).ConfigureAwait(false);inside anasyncmethod. The awaited form allocated a state machine per call whose only job was to re-wrap the task the request builder had already produced.What is the current behavior?
Task-returning methods on the reflection fallback path are emitted
asyncand await the request builder's task before returning it, allocating a second state machine on every call to that method.What might this PR break?
BuildRestResultFuncForMethod, previously surfaced as a faulted task; it now throws from the call itself. Callers that invoke a fallback method without awaiting it, and rely on catching around theawait, need to catch around the call. Inline-built methods already behaved this way.ApiExceptionBase.HttpMethod,.Uri, and theRefit.MethodName/Refit.RelativePathTemplaterequest options.Checklist
mainbranchAdditional information
The fallback emission shape had no test coverage, so the change would have gone unnoticed by the suite.
SwitchOnFallbackReturnsTheRequestBuilderTaskWithoutAwaitingnow pins it.A sweep of the runtime for the same pattern found nothing to remove. Every remaining
asyncmethod needs its state machine: ausingortryscope that has to outlive the await, sequential awaits, work after the await, or an async iterator. Two methods forward a single call but convertValueTask<T>toTask<T>across the boundary, where eliding would mean an unconditionalAsTask()allocation in place of a state-machine box that is only allocated when the await actually suspends.