Repository navigation
Conversation
Add net11.0 to the library and the unit test project. All existing target frameworks (netstandard2.0, net6.0-net10.0) are kept. The newest target framework keeps the apphost in the test project. Tooling and docs follow: dev container installs SDK 11 plus the older SDKs, test environments use the released .NET 10 and .NET 11 images, the project script defaults to net10.0, and the README lists .NET 11.0. Refs #958
…der overloads On net8.0 and newer the pending path now waits with Task.WaitAsync and ConfigureAwaitOptions.SuppressThrowing instead of a linked CancellationTokenSource, Task.Delay and Task.WhenAny. This removes about half of the allocations and a thread pool hop when the task completes in time. netstandard2.0, net6.0 and net7.0 keep the previous implementation. Observable behavior is the same on every target framework: no exception on timeout, the exact OperationCanceledException with the caller's token, faults rethrown unchanged, and the same ArgumentOutOfRangeException for timeouts beyond the timer limit. New tests pin these cases and pass on the previous implementation as well. Add WithTimeoutAsync(TimeSpan, TimeProvider, CancellationToken) overloads for Task, Task<T>, ValueTask and ValueTask<T> on net8.0 and newer, so timeouts can be tested deterministically. Refs #958
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #959 +/- ##
==========================================
- Coverage 99.16% 97.16% -2.00%
==========================================
Files 10 10
Lines 239 353 +114
Branches 40 61 +21
==========================================
+ Hits 237 343 +106
- Misses 0 6 +6
- Partials 2 4 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Compile the net11.0 asset with the runtime-async feature, so the runtime suspends and resumes async methods instead of compiler generated state machines. Older target frameworks are compiled as before. Refs #958
…sync WhenAll awaits once per supplied task inside one method. With Runtime Async every suspension and resumption costs more than with a compiler generated state machine, which made WhenAll over pending tasks about 30 to 50 percent slower on net11.0. Opt the WhenAll methods out per method; WithTimeoutAsync stays on Runtime Async. The attribute is recognized by the compiler by name and has no effect on target frameworks that are compiled without the runtime-async feature. Refs #958
The pending path went through a second async method. Each public overload now awaits Task.WaitAsync in its own frame, with the shared logic in two synchronous helpers. This saves one async frame per pending call: 152 to 168 B less and about 20 percent faster on net11.0. Behavior is unchanged; netstandard2.0, net6.0 and net7.0 keep the previous code path. Refs #958
Measured on the final code, Runtime Async costs this library on every path: 104 to 152 B more per pending WithTimeoutAsync call and about 20 percent more time, and 1.3x to 1.5x for WhenAll over pending tasks. With every async method opted out the feature switch has no effect left, so the switch and the per-method opt-out are removed again. Refs #958
… on net8+ The Task.WaitAsync based path differed from the previous implementation in three ways. All three are restored: - When the task completes in time, the caller resumes on the thread pool again instead of inline on the thread that completed the task. - The outcome is read from the result of WaitAsync, which records what happened first, instead of from the state of the task afterwards. A task that completes right after the timeout elapsed reports false again, and right after the caller's cancellation throws again. Tests pin the resuming thread per target framework and a task that is canceled itself while waiting. Refs #958
…work The released implementation resumed the caller inline on the thread that completed the task. Since the cancellation fix, net8.0 and newer went through CancellationTokenSource.CancelAsync, which moved the caller to the thread pool as a side effect. Restore the initial behavior: no thread pool hop on any target framework. The first-wins outcome and the exact OperationCanceledException of the cancellation fix are kept. A test pins the resuming thread. Refs #958
This branch has not been deployed
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.
Summary
Adds
net11.0to the library and the tests, and modernizes the internals ofWithTimeoutAsynconnet8.0and newer. All existing target frameworks are kept. The way the library works is not changed, on any target framework.Refs #958
Changes
Target framework
net11.0added to the library and the unit test project; the newest target framework keeps the apphost.testEnvironments.json,new-project.ps1(defaultnet10.0) and the solution README template updated.WithTimeoutAsynconnet8.0+Task.WaitAsyncwithConfigureAwaitOptions.SuppressThrowinginstead of a linkedCancellationTokenSource,Task.DelayandTask.WhenAny, awaited directly in each public overload (one async frame instead of two).netstandard2.0,net6.0andnet7.0keep the previous implementation unchanged.mainon .NET 8, 10 and 11, task completing before the timeout: 4.5x to 9x faster (about 2000 to 3100 ns down to 300 to 490 ns) and 60 to 65 percent fewer bytes (about 1130 to 1220 B down to 400 to 490 B). Timeout elapses: time unchanged, 111 B more on .NET 8, 50 B less on .NET 10 and 11. Already completed tasks andWhenAll: unchanged.New API (
net8.0+)WithTimeoutAsync(TimeSpan, TimeProvider, CancellationToken)forTask,Task<T>,ValueTaskandValueTask<T>, for deterministic timeout tests.Behavior
Kept identical on every target framework and pinned by tests that also pass on the previous implementation:
Task<T>/ValueTask<T>still deliver the late resultOperationCanceledException(notTaskCanceledException) carrying the caller's token; a task that is canceled itself surfaces its ownTaskCanceledExceptionTimeoutExceptionTask/ValueTaskstill reportstrueArgumentOutOfRangeExceptionwith parameter namedelayfor timeouts beyond the timer limitWaitAsync, which records the first of completion, timeout and cancellation, likeTask.WhenAnydidnet8.0+ had picked up throughCancellationTokenSource.CancelAsyncin feat(ValueTask): add WhenAll extension members and fix WithTimeoutAsync cancellation #956 is gone again.Known remainder: if the timeout elapses and the task faults in the same instant, the result is still
false, but the exception of the task counts as observed, soTaskScheduler.UnobservedTaskExceptionis not raised for it.Not changed, on purpose
#if !NET11_0_OR_GREATERgating: the .NET 11 BCL has noValueTask.WhenAll,ValueTask.WhenAnyorValueTask.WaitAsync.<Features>runtime-async=on</Features>) was tried for thenet11.0asset and removed again: every suspension is more expensive than with a compiler generated state machine, measured 1.3x to 1.5x forWhenAllover pending tasks and 104 to 152 B more per pendingWithTimeoutAsynccall.WhenAll: untouched.global.json,Directory.Build.props,Directory.Packages.props,.editorconfig: untouched.NE_DOTNET_TARGETFRAMEWORKSalready contains11.x.Verification
dotnet build -c Release: 0 warnings, 0 errors on all 7 target frameworks.dotnet test: 1106 tests passed on net6.0 to net11.0, three consecutive runs.dotnet pack: package containslib/net11.0next to all previous target framework folders.