Session

Mechanical Sympathy in Go

The workshop is lab-centric. I will provide a prepared GitHub repository containing a suite of sub-optimal Go benchmarks. For each module, we follow a three-step process:

The "Under the Hood" Briefing: A deep dive into the specific runtime/compiler mechanic (e.g., how the P-M-G scheduler model works).

Observation: Running pprof, benchstat, and compiler flags (-m -l) to "see" the bottleneck.

The Refactor: Attendees apply "Mechanical Sympathy" to the code and re-benchmark to validate the theory.

Detailed Outline
Phase 1: The Diagnostic Suite (Tooling)

Benchmarking & Statistics: Using testing.B and benchstat to get reliable data.

Profiling: Identifying hot paths with pprof (CPU and Heap).

Execution Tracing: Using go tool trace to visualize latency and scheduler behavior.

Phase 2: Memory & Data Layout

Allocation Mechanics: The cost of mallocgc. We’ll explore Slice/Map pre-allocation and how it impacts the backing array.

Reuse Patterns: Implementing sync.Pool to alleviate GC pressure in high-throughput systems.

Hardware Alignment: A lab on Structure Packing—showing how field ordering changes memory footprint and cache-line efficiency.

Phase 3: The Compiler’s Decisions

Escape Analysis: Identifying why variables move to the heap and how to "keep them on the stack."

Inlining: Understanding the budget and boundary of the inliner to reduce function call overhead.

Phase 4: Concurrency & The Scheduler

The G-M-P Model: How Go manages thousands of goroutines.

Scheduler Affinity: Patterns to avoid "work stealing" overhead and minimize context switching.

Channel vs. Mutex: Real-world benchmarks comparing synchronization primitives under high contention.

The exact outline can change in the future, but my expectation is to not change substantially.

I'm ok on converting this one in a 6 hours workshop, but I don't know if that is going to be too exhausting.

Jesús Espino

Principal Engineer at VictoriaMetrics

Guadalajara, Spain

Actions

Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.

Jump to top