Earlier quoted context omitted.
Goroutines + channels add an enormous amount of overhead. Using them as iterators is basically insane.
It’s not insane at all. How did you come to that conclusion? * Mutex lock+unlock: 10ns * Chan send buffered: 21ns * Try send (select with default): 3.5ns Missing from here is context switches. In either case, the overhead is proportional to how fast each iteration is. I have channels of byte slices of 64k and the channel ops don’t even make a dent compared to other ops, like IO. You should absolutely use channels if…
Exactly. From rsc's previous post[1]:
> On my laptop, a C thread switch takes a few microseconds. A channel operation and goroutine switch is an order of magnitude cheaper: a couple hundred nanoseconds. An optimized coroutine system can reduce the cost to tens of nanoseconds or less.
[1]: https://research.swtch.com/pcdata>