Go under the hood
Go: Under the Hood

Chapter 9 The goroutine Scheduler

(Execution stack management originally belonged to this chapter; it has now been moved to Chapter 14 Execution Stack Management.)

The performance improvement does not materialize from the air, it comes with code complexity increase.
-- Dmitry Vyukov

In the author’s eyes, the Go scheduler is the most fascinating component in the entire runtime. For Go itself, its design and implementation directly affect every other component of the Go runtime, and it is the part that deals directly with user-space code. For Go users, the scheduler hides an extremely complex runtime machinery behind a single simple keyword, go. To guarantee high performance, the scheduler must make effective use of the parallelism and locality of computation; to keep user space simple, the scheduler must efficiently schedule the network poller and the garbage collector, which are invisible to user-space code; to guarantee the correctness of code execution, it must also strictly implement the memory ordering of user-space code, and so on. In short, the design of the scheduler directly determines the form that the Go runtime source code takes.