Chapter 04The Compiler's Optimization BudgetPaid chapter

Inlining — Budgets, Costs, PGO, and What Breaks It

Understand Go's inlining cost model, what causes functions to exceed the budget, how PGO changes the decision, and why inlining loss cascades into escape and allocation regressions.

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

Extracting a helper function is free; the compiler inlines small functions anyway.

What actually happens

inlining is gated by an AST-node cost budget (80). One node over and the whole function stops inlining — which can cascade into lost escape analysis and new allocations. PGO can raise the budget for hot call sites.

Mechanisms covered
Mid-stack inlining (Go 1.19+) inlines callers of inlinable callees, but the combined cost must fit the budget.
PGO (Profile-Guided Optimization, stable since Go 1.21): with a default.pgo profile in the main package, the compiler raises the inlining budget for hot call sites identified in the profile, inlining functions it would otherwise reject.
Inlining enables further optimizations: escape analysis sees through inlined calls, BCE proves bounds across inlined code, register allocation improves.
compilebench
Email-first checkoutUnlock Chapter 04

Unlock Chapter 04 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.