Reflection and internals
A program can read its own types at run time, and it pays for that. These lessons cover reflect and struct tags, the reflection inside encoding/json, the memory model, escape analysis, the garbage collector, the metrics the runtime exposes and the directives the compiler reads. They explain why the choices of the earlier parts behave the way they do.
9.1
reflection: types and values
reflect.TypeOf and ValueOf, Kind against Type, a field read by name and the panic of a wrong kind
Open
9.2
Struct tags
a tag on a field, reflect.StructTag.Get, a tag read by a library and the syntax the compiler checks
Open
9.3
How encoding/json uses reflection
the field walk, the tag names, the cached type information and what a custom Marshaler changes
Open
9.4
The Go memory model
happens-before, a channel that publishes a write, a mutex that orders and the race the model forbids
Open
9.5
Escape analysis and allocations
-gcflags=-m, a value that stays on the stack, one that escapes and the allocations a profile shows
Open
9.6
The garbage collector
the concurrent collector, GOGC, GOMEMLIMIT, a finalizer and the pause a program sees
Open
9.7
Runtime metrics and traces
runtime/metrics, runtime.ReadMemStats, a trace with go tool trace and the numbers worth watching
Open
9.8
Compiler directives and intrinsics
//go:noinline, //go:nosplit, //go:linkname and the directives a program should not need
Open