4 ms·
> But there are some disadvantages to this way of doing it. First, we have to wait until the whole slice has been generated before we can start to process the f
by ilyt 3y ago
> But there are some disadvantages to this way of doing it. First, we have to wait until the whole slice has been generated before we can start to process the first element of it.
Uh, range over channel ? The author seems to be very bad at go
func Items() (items chan Item)
will return channel that then can be just
for a := range Items() {}
- progbits 3y agoChannels come with significant overhead [1]. While that is fine (or unavoidable) when communicating between goroutines, in single threaded code that iterates some custom container you don't want a channel. That is why stdlib map and vector have their own range magic, but as library author this isn't available to you. That is the point of the proposal. [1] https://syslog.ravelin.com/so-just-how-fast-are-channels-anyway-4c156a407e45 https://syslog.ravelin.com/so-just-how-fast-are-channels-any...
- masklinn 3y agoChannels are also not great when you want to break off / cancel iteration. The overhead also compounds when you compose / chain iterators. Plus the "lag" they induce due to context switching, although I think I saw an optimisation (proposal) where the runtime would directly switch from one routine to the other in some cases of channel interactions? Or am I thinking of an other language entirely?
- agent281 3y agorsc also talked about the performance of channels vs coroutines in his blog post. If memory serves, it was 10x reduction in looping overhead. https://research.swtch.com/coro https://research.swtch.com/coro