I've already known that the runtime.morestack
will cause goroutine context switch (If the sysmon goroutine has marked it "has to switch").
And when I do some experiment around this, I've found an interesting fact.
Compare the following codes.
func main() {
_ = make([]int, 13)
}
func main() {
_ = make([]int, 14)
}
And compile them by running the following command: (Tried in go1.9 and go 1.11)
$ go build -gcflags "-S -l -N" x.go
You may find a major difference that the first outputs contains CALL runtime.morestack_noctxt(SB)
while the second doesn't.
I guess it is an optimization, but why?