Considering the latest version of the channel, this is not a trivial structure:
type hchan struct { qcount uint // total data in the queue dataqsiz uint // size of the circular queue buf unsafe.Pointer // points to an array of dataqsiz elements elemsize uint16 closed uint32 elemtype *_type // element type sendx uint // send index recvx uint // receive index recvq waitq // list of recv waiters sendq waitq // list of send waiters lock mutex }
Waiter line items are also quite heavy :
type sudog struct { g *g selectdone *uint32 next *sudog prev *sudog elem unsafe.Pointer
You see, a lot of bytes. Even if an element were created for an empty channel, this would be negligible.
However, I expect all empty channels to occupy the same space regardless of the base type, so if you only intend to close the channel, there will be no difference (the actual element seems to be held by the pointer). A quick test supports it:
package main import ( "fmt" "time" ) func main() {
I do not see the difference between chan struct{} and chan [64000]byte , and this leads to ~ 1 GB of use on my 64-bit machine, which makes me think that the overhead of creating one channel is approximately 100 bytes.
In conclusion, this is not a big deal. Personally, I would use struct{} , since it was the only really empty type (size 0 really), which clearly indicates the absence of intent on any sent payload.
source share