rgoussu@goussu: ~/library/go
~/library/go cat go-deep-dive.md

Deep dive Go

# Go beneath the surface — goroutines and the scheduler, channels and CSP, interfaces, the GC, and the language's deliberate simplicity.

Conceptsaved 2026-08-08updated 2026-08-09 #go#concurrency#internals#runtime

Overview

Go's design bet is radical simplicity: a small language, fast compilation, and one first-class concurrency story (goroutines + channels, from Hoare's CSP) baked into the runtime. Going deep means understanding that runtime — the M:N scheduler, the GC, how interfaces dispatch — and the idioms the community has settled on, because Go punishes fighting its grain more than most languages.

Key points

  • Goroutines & scheduler: G-M-P model (goroutines multiplexed onto OS threads via per-core run queues), work stealing, preemption; goroutines cost ~KBs — concurrency as a default, not an event.
  • Channels & CSP: "share memory by communicating"; buffered vs. unbuffered, select, context.Context for cancellation as the idiom that ties it together; sync package when channels are the wrong tool.
  • Interfaces: implicit satisfaction, small interfaces (io.Reader) as the design unit; interface values = (type, pointer) pairs — the nil-interface trap.
  • Memory & GC: escape analysis (stack vs. heap), concurrent tri-color mark-sweep tuned for low pause over throughput, GOGC/GOMEMLIMIT.
  • Error handling & generics: explicit error returns, wrapping with %w, errors.Is/As; generics (1.18+) deliberately modest — used for containers and constraints, not type gymnastics.
  • Tooling as language feature: go mod, gofmt (no style debates), race detector, pprof profiling, single-binary cross-compilation.
  • To explore: runtime internals (netpoller under goroutine I/O), PGO, when Go's simplicity becomes a ceiling (and the workarounds).

Practice

  • Go by Example (source) — annotated idiomatic snippets to type through, not read; the fastest route to the community's settled idioms.
  • Gophercises (source) — small complete programs (quiz game, URL shortener, link parser) that exercise interfaces, goroutines, and the standard library the way real Go does.
  • Coding Challenges in Go (source) — build your own wc, Redis, or load balancer; single-binary tooling makes Go the natural vehicle.
  • Protohackers ladder (source) — the flagship: network servers from echo to shared-state chat to proxy, one goroutine-and-channels pattern per rung, race-detector clean.

Related