-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider StartImmediateAsTask
instead of StartAsTask
to prevent a thread hop
#135
Comments
This seems relevant as well: dotnet/fsharp#11043 (comment) That comment by @dsyme basically suggests not to use I figured, maybe just report as a bug to F#: dotnet/fsharp#14490 |
Thanks for bringing this up @bartelink. It required some digging, and writing a context-switching test case, but I'm now convinced this is a bad situation to be in (tbh, as Don mentioned already, these methods should be differently named). Will write a PR to fix it. |
- [StartAsTask -> StartImmediateAsTask](fsprojects/FSharp.Control.TaskSeq#135) Credits @TheAngryByrd
The thread hop in F# Core |
In PR #114 (adding support for
Async
inBind
), @bartelink raised the question whether it would be better to useStartImmediateAsTask
instead ofStartAsTask
.Specifically, it is about this part:
The current approach was taken to mimic the same approach taken for
task
in F# Core: https://github.com/dotnet/fsharp/blob/d91b6c5c97accf363d135d1f99816410da4ec341/src/FSharp.Core/tasks.fs#L462, basically:For comparison, see what was done in
async2
, which was poised to be the newasync
based on resumable code, liketask
is, but unlike task cold-started like the currentasync
.So, we have two scenarios:
StartAsTask
to get similar semantics as thetask
CE, but this causes a thread hopStartImmediateAsTask
, which uses the current contextI'm not aware of any downside of using the latter. It definitely saves a thread switch in the general case (note that the thread pool may not always cause a physical thread switch).
The text was updated successfully, but these errors were encountered: