Re:Go Things I Love: Channels and Goroutines
by skohan on Tuesday January 07, 2020 @05:38AM
(#21978727)
What are the performance characteristics of channels? I do some work with computer graphics, and a lot of the concurrency concerns involve operating on large chunks of memory (textures, vertex buffers etc) and my mental model is that channels involve a lot of copying, so you would pay a heavy cost for sending these heavy objects back and fourth. But I have no idea if my mental model is correct.
[ Parent
| on HN ]
Re:Go Things I Love: Channels and Goroutines
by twic on Tuesday January 07, 2020 @08:35AM
(#21979747)
You'd pass pointers to the buffers over the channels, so there wouldn't be much copying.
You would need to be careful that once one goroutine has sent a pointer to a channel, it doesn't touch that buffer again (until the receiver has finished with it, at least), otherwise you can get data races. You're implementing ownership semantics here, and unlike in some languages i could name, you're doing it without help from the type system.