Go Mechanics Workshop
A hands-on workshop exploring Go's internals — from the compiler pipeline to the runtime scheduler, memory allocator, and garbage collector. Modify the Go source code to deeply understand the machinery behind the language.
14 exercises covering the full Go stack.
This workshop has 14 exercises covering the full Go mechanics stack — compiler pipeline, memory allocator, garbage collector, goroutine scheduler, and core data structures. Each section is a hands-on exercise where you modify Go itself:
Introduction and Setup
Set up your environment by installing Go and cloning the Go 1.26.1 source code.
Build Go from Source
Bootstrap the Go toolchain from source and explore the compiler and runtime directories.
Lexer & Scanner — Arrow Operator
Add '=>' as an alternative goroutine syntax by modifying the scanner.
Parser — Multiple 'go' Keywords
Allow 'go go go fn()' syntax by modifying the parser.
Escape Analysis & Inlining — The Greedy Inliner
Tune the inlining budget, measure binary size, and find the runtime's hard ceiling.
SSA & Compiler Backend — Power-of-Two Detector
Create a custom SSA pass that finds divisions by powers of two.
Memory Allocator — The Superstitious Allocator
Make the allocator panic on unlucky allocation sizes to expose the internals.
Goroutine Stack — Big-Boned Goroutines
Start every goroutine with a 1MB stack and observe the memory impact.
GMP Scheduler — Patient Go
Make the runtime wait for all goroutines before the program exits.
Work Stealing — D&D Dice Roll
Gate goroutine theft with a d20 dice roll.
Garbage Collector — Anxious GC
Make the GC run aggressively by lowering its trigger threshold.
Slices & Maps — Explosive Growth
Change the slice growth factor to 10x and make maps rehash obsessively.
Channels & Select — Predictable Select
Remove randomness from select to make it always pick the first ready case.
Panic & Defer — Java-Style Stack Traces
Transform Go's stack traces to look like Java's.
Prerequisites
You should know / have
- Solid knowledge of Go programming
- Familiarity with command line tools
- Git installed on your system
- Go compiler version 1.24.6 or newer (required for bootstrapping the build)
- At least 4GB of free disk space
- A curious mind and willingness to break things
Getting started
- Start with Exercise 0 to set up your environment
- Work through exercises 0 and 1 in order (setup + first build)
- After that, each section is self-contained — pick what interests you