-
Notifications
You must be signed in to change notification settings - Fork 782
4.x: Proposal ~ one-time internal Scheduler API #598
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
Conversation
|
So what we're essentially looking for is to bake some fire-and-forget-and-never-schedule-recursively mechanism into the schedulers, like it is now mimicked by the |
|
Yes, but not only for the client, but for the service provider so it doesn't have to waste resources on a unneeded feature. |
|
I'm thinking about how to bring this together with the already existing extension methods for non-recursive scheduling. Ideally, if default interface implementations were a thing in C# today, I guess we would use them here, executing what the extension does today. I'm also thinking about somehow smarting up the existing extension so that it may detect the ability of one-time-scheduling. And then, would renaming the one-time-methods to simple |
|
This PR is about providing a different API when the operator is known to issue exactly one schedule on a standard scheduler and not conveniencing a call over the regular schedule call that has an IScheduler still provided but suppressed in those helper methods you contributed. |
|
So just to understand it right, the operators that would take advantage of a one time scheduler would, in their API, still take an |
|
The operators would still take their usual IScheduler, but they would feature detect the direct schedule ability. That requires support and specialized implementation on the schedulers that want to support it. |
|
So it could be centralized into the existing extension which could do the feature detection? |
|
Like e.g. the Count() extension of Linq checks the enumerable if it implements |
|
That's a matter of convenience, like having this part of |
|
Convenient is good, so the improvement can be leveraged by anybody who maybe doesn't know about IOneTimeSchedulers. Just one more thing, the name |
Assuming the |
|
At least for the ImmediateScheduler, the semantic equivalency is obvious. I leave it up to you whether to push it into the extension, IMO the overhead of the Maybe we can still align the namings, there are now 3 terms around that essentially mean the same ( |
|
If cast to I'd like to keep it scoped to |
|
Ambiguity should be no problem, interface methods are closer than extension methods and will always be preferred. |
|
So...does the 'proposal' in the PR-text suggest this is not ready to merge, or is this good to go? |
|
The PR is operational, it just needs a decision about going into this direction. |
|
I'm all for it, I only feel it should be the 'pit of success', that is, the improvement should be there for anybody who doesn't want to deal with the different concepts of schedulers. Thus my proposal to put it in the extension. We could, for a first step, try to make all non-recursive schedulings in the library explicit, by using |
|
How should this advance? |
|
I don't know. I certainly don't want to affect any operator that happens to use |
|
What could happen if the changes would go into |
|
Currently, only a few would benefit:
other uses either recurse in a different fashion or work with a scheduler that presents itself as the recursive scheduler. |
|
I'll post a replacement PR where I only modify the operators above and measure the effects via benchmarks. |
While looking at the Scrabble benchmark for hints of likely unnecessary allocations, I've come across
Returnwhich by default usesImmediateSchedulerto emit its single item. This scheduler simply executes theactionit gets immediately but due to the standardISchedulerAPI, it has to provide an "inner" recursive scheduler to theFunc. WithReturn, there won't be any further calls to theISchedulerAPI so thisAsyncLockSchedulerallocated is wasted.I'm proposing a shortcut in the form of the
IOneTimeSchedulerinterface that doesn't allow recursive scheduling and this PR shows a way to implement it insideImmediateSchedulerand the use of it inReturn. The API is a simple asScheduleDirect(TState, Action<TState>); it usesActionbecause returning anIDisposablemakes not much sense - there is no task to follow up and keep referencing after the one-time action has finished.Of course,
Returncould be simply have a special case when itsscheduleris theImmediateSchedulerand emit directly.