-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: change default max channel size to typemax(Int) #17698
Conversation
What is the downside for unlimited? |
Point 1 above - Having an unlimited max size would mean a producer task could fill up a channel before any consumers were run - especially since we don't have tasks switched on multiple threads yet. User code would need to explicitly specify an appropriate buffer size for the problem at hand. This is true only if the producer is purely compute bound and does not yield. |
This is a behavior change and should wait until we branch IMO. |
My impression is that channels with unlimited buffers are a bit dangerous, no? |
Pros and cons of various defaults:
I am veering around to Golang's unbuffered channels as the default now, i.e., a default of size 0. Safest and when documented users are aware that the buffer size has to be explicitly specified depending on the nature of the workload. |
What about no default? Then someone has to read what that argument is and what the different values mean and what the tradeoffs are (similar to the above pro/con list). |
No default is fine too. |
Let's go with that for now and if it becomes apparent in the future that On Wednesday, August 3, 2016, Amit Murthy notifications@github.com wrote:
|
Superseded by #18832 |
Currently, if the size is unspecified,
Channel()
creates a channel with a max size of 32. The rationale for this at that time werePartially mimic the produce-consume lockstep task switching wherein each depended on the other. Having an unlimited max size would mean a producer task could just fill up a channel before any consumers were run.
It was mainly relevant when the implementation used a circular buffer which grew dynamically but was never shrunk. Now the backing store is an Array which resizes depending on the number of elements present.
I think the default should either be 0, 1 or unlimited(i.e.,
typemax(Int)
) with my preference for unlimited.A max size of 0 (which is currently not supported) would mimic golang's channels which require produce and consume to run in tandem, i.e., a
put!
on a channel of size 0 would block till atake!
is called.