Chapter 10The Price of AbstractionPaid chapter

Generics — GCShape Stenciling and What Go Actually Does

Understand Go's generic compilation strategy, when generics approach monomorphic performance, and when they don't.

Launch paywall

This chapter is part of the paid launch. The preview stays visible so readers can evaluate the exact scope before buying.

Included in

Core, Complete, and Team. Complete also includes the practical exam and free Go-version updates.

Preview

What this chapter teaches

Common belief

Generics are zero-cost, like C++ templates.

What actually happens

Go uses GCShape stenciling — value types get dedicated code (near-monomorphic), but all pointer types share one body with a runtime dictionary (measurable overhead). It's neither full monomorphization nor type erasure.

Mechanisms covered
Generics over value types give near-monomorphic performance. Generics over pointer types have dictionary overhead but avoid the heap allocation that interfaces cause.
Neither full monomorphization (C++ templates) nor pure type erasure. The result depends on the type parameter shape.
compilebench
Email-first checkoutUnlock Chapter 10

Unlock Chapter 10 and the rest of the course.

Start with your email, then continue to Lemon Squeezy checkout. Core unlocks the paid chapters, Complete adds the exam and free Go-version updates, and Team gives you 5 seats.

Choose a plan

You'll head to Lemon Squeezy for secure checkout. Global tax is handled there. No subscription. Complete also includes the practical exam and free Go-version updates.

Free chapter
Escape Analysis — The Compiler's Fragile Decision
Understand how the compiler decides between stack and heap allocation, why the decision is fragile, and how to verify it.
Free chapter
Maps — Swiss Tables, Growth, and Permanent Memory
Understand the Go 1.24+ Swiss Table map layout, why maps don't shrink, and how to design for memory reclamation.