-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Refactor Binds to Source members #12
Conversation
@dsyme do you know of any reason I should not use |
Let's /cc @gusty. He mentioned to me the other day that this has been around since a long time, but only covered in the spec, not in docs. As far as I know this is safe to do, but maybe Gus can glance over these changes if he knows the intrinsics of this approach? |
Not as far as I know @TheAngryByrd. There are of course some overload resolution cases where having the continuation arguments in the same resolution as the value can influence the outcome to be a better fit but in almost all cases I've been able to restructure to still be able to use Source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty awesome change. Are the timing differences due to .NET 7 or caused by the move to Source
? They are quite impressive.
@@ -324,6 +324,8 @@ module Helpers = | |||
[<CategoriesColumn>] | |||
type AsyncBenchmarks() = | |||
|
|||
let getTempFileName () = | |||
Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought: if you dump these in an IDisposable
, you can actually delete the files after the tests. Or use setup/teardown, which I believe BenchmarkDotnet also supports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, i need to steal my disposabledirectory/file code from other repos
| AsyncBinds_cancellableTask_bindCancellableTask | AsyncBinds | 20,201.2 μs | 400.21 μs | 852.88 μs | 20,049.0 μs | 1.25 | 0.15 | 31.2500 | - | - | 320 KB | | ||
| Method | Categories | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | | ||
|------------------------------------------------ |-------------- |-------------:|-------------:|-------------:|-------------:|-------:|--------:|-----------:|-------------:|------------:| | ||
| AsyncBinds_CSharpTasks | AsyncBinds | 3,329.6 μs | 28.27 μs | 26.45 μs | 3,334.1 μs | 1.00 | 0.00 | 3.9063 | 109.39 KB | 1.00 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (AsyncBinds_CSharpTasks /AsyncBinds
) went from 17μs to 3μs? Is this due to the changed setup or can "old vs new" be compared? It's a pretty amazing perf gain!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't read too much into these as this has changed machines.
and ^Awaiter: (member get_IsCompleted: unit -> bool) | ||
and ^Awaiter: (member GetResult: unit -> 'TResult1)> | ||
( | ||
sm: byref<ResumableStateMachine<CancellableTaskStateMachineData<'TOverall>>>, | ||
task: ^TaskLike, | ||
[<InlineIfLambda>] getAwaiter: CancellationToken -> ^Awaiter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this makes a difference, since the argument is already static (i.e., it uses an SRTP constraint, so it has to be inlined). Did you see a difference in the generated code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I still haven't gotten around to investigating the different state machine generation and yeah I'm unsure how often I'd actually need InlineIfLambda
if at all in most cases in this file anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For (some) insights, see this answer by Don: dotnet/fsharp#14123 (comment)
I don't think there's something special about |
@gusty I think the main use-case here is that by using The main question at hand is: is there any caveat to using it? (also asking because of my own interest in the method). |
Well, you're saving keystrokes there already. Ideally the user should explicitly convert. Moving it to Source won't change anything in that regard. But going to your main question:
Not that I know. I never used it in my OSS projects, but I used it in many prototypes and I wouldn't hesitate to use it in any OSS project, it's just that I still didn't find a problem that it would solve there. |
Great, thanks! Looking at the diff here, the main use case is simplification. That, of course, isn't needed in each and every CE. |
Thank you everyone for your feedback. Highly appreciated! |
## [0.3.2-beta001] - 2022-11-30 ### Changed - [Refactor Binds to Source members](#12) Credits @TheAngryByrd
## [0.3.2-beta002] - 2022-11-30 ### Changed - [Refactor Binds to Source members](#12) Credits @TheAngryByrd - [Expand TFMs to netstandard2.0 and 2.1](#13) Credits @TheAngryByrd - [InlineIfLambda was just adding compile time without benefit](#14) Credits @TheAngryByrd - [Refactor Binds to Source members](#12) Credits @TheAngryByrd
## [0.3.2] - 2022-11-30 ### Changed - [Refactor Binds to Source members](#12) Credits @TheAngryByrd - [Expand TFMs to netstandard2.0 and 2.1](#13) Credits @TheAngryByrd - [InlineIfLambda was just adding compile time without benefit](#14) Credits @TheAngryByrd
Proposed Changes
This uses the
Source
member overloads to provide a more stripped down version of the ColdTask and CancellableTask CEs.Similar to the work I did in demystifyfp/FsToolkit.ErrorHandling#83
Types of changes
What types of changes does your code introduce to IcedTasks?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...