3 ms·
Channels come with significant overhead [1]. While that is fine (or unavoidable) when communicating between goroutines, in single threaded code that iterates so
by progbits 3y ago
Channels 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