Optimize waker size for requirements #40
Draft
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 is the result of me tinkering around with the idea described in #4, I would like your approval/disapproval on the basic idea before i write documentation etc.
TLDR; It's possible to reduce the size of a
ReceiverWakerif it is known that it will only be used in blocking or non-blocking contexts beforehand. This is currently being decided using crate features, but it would be nice if it was possible to specify this for each channel individually.Design Idea
This PR uses two traits (
SyncWaker/AsyncWaker) to expose different methods onReceiverbased on what waker is being used.There are four different wakers, which are equivalent to the four possible feature combinations right now:
SyncWakerAsyncWakerReceiver<T, W>DummyWakertry_recvonlythread::Threadtask::WakerGenericWakerTo avoid breaking changes, a
DefaultWakeris also exported, which equates to the "most permissive" of the available wakers based on the enabled features and, as the name implies, is used by default.The main design issue currently is how to adjust the crate API so the used waker can be specified.
Currently, channels are being constructed using
Ideally this would be possible:
but default values for generic parameters on functions are not allowed.
So the "next best" option would be to either export more constructor functions:
or to move these functions onto the
Channeltype itself, so the waker type is already clear.