JIT: Add an opportunistic optimization to reuse continuation instances #121090
+149
−35
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 adds an optimization that tries to reuse the continuation instance that was used to resume a runtime async function if it suspends again.
This optimization is not reliable. It only kicks in if the same suspension point resumes and then suspends again. However, it is useful to get an idea of how costly the continuation allocation part is when looking at the gap between
async1 and runtime async in raw suspension/resumption performance.
The optimization is controlled by
DOTNET_JitOpportunisticContinuationReuseand is disabled by default.Despite the above this is not a very costly transformation, so we may consider enabling it even if it does not kick in very reliably.
Example benchmark that measures raw suspension/resumption performance (best case for async1, worst case for runtime async):
With
DOTNET_JitOpportunisticContinuationReuse=0: Took 5788.9 msWith
DOTNET_JitOpportunisticContinuationReuse=1: Took 4611.5 msAsync1: Took 3433.7 ms