PGO or not PGO this is the dilemma. Step 2
Recorded: Oct. 16, 2026, 10:11 p.m.
| Original | Summarized |
PGO or not PGO this is the dilemma. Step 2 - Percona
Download the New 2026 State of Open Source Database Management Report Database Technology PostgreSQL PostgreSQL Percona Software for PostgreSQL Calculator Downloads Enterprise Support and Services MySQL Vision MySQL Percona Software for MySQL Calculator Downloads Enterprise Support and Services MariaDB MongoDB® Technology Overview Percona Software for MongoDB® Calculator Downloads Enterprise Support and Services Valkey / Redis Valkey / Redis Calculator Downloads Enterprise Support and Services Databases on Kubernetes Observability Monitoring & Management (PMM) Coroot Percona Edition Percona Toolkit Services Solutions Bundles Database Support Expert Support ExpertOps Expert Consulting and Services Migrations Use Cases Use Cases Database solutions aligned to your needs Learn More Cost Optimization Reduce licensing waste and optimize database cost and performance Performance and Reliability Maintain consistent performance and availability as workloads grow Sovereignty, Security, and Compliance Keep data secure, compliant, and under your control AI and Future Readiness Prepare for AI and new workloads without lock-in or replatforming Resources Resources Guides, reports, and tools to help you run open source databases in production Docs Downloads Resource Hub Blog Customer Stories Webinars Community Forum Ask questions, share knowledge, and learn from the community. Community Hub Join the Percona Community Events Connect with us via talks, workshops, and meetups. Company About Percona Learn about Percona, our mission, and our open source roots. Learn More News Press Releases Partners Careers Contact Brand Resources × Main site See all results → Downloads Blog Contact Us Database Technology MySQL Vision MySQL Percona Software for MySQL Calculator Downloads Enterprise Support and Services MongoDB MongoDB Percona Software for MongoDB Calculator Downloads Enterprise Support and Services PostgreSQL PostgreSQL Percona Software for PostgreSQL Calculator Downloads Enterprise Support and Services Valkey / Redis Valkey / Redis Calculator Downloads Enterprise Support and Services Operations Monitoring Percona Toolkit Services Support & Operations Expert Support ExpertOps Training Advisory & Solutions Support & Services Expert Consulting Solution Bundles Use Cases Overview Use Cases Operational Outcomes Cost Optimization Performance and Reliability Sovereignty, Security, and Compliance Future Readiness AI and Future Readiness Resources Developers Docs Downloads Hub Resource Hub Blog Customer Stories Webinars Percona Community Forum PMM Contributions Events Company About Percona News and Press Partners Careers Contact Us PGO or not PGO this is the dilemma. Step 2 October 9, 2026 Author Marco Tusa Marco Tusa
Insight for DBAs
Insight for Developers
MySQL
Share this Post: Step 2: How it works What is PGO How PGO works: PGO is a two-pass build. First pass compiles with instrumentation (-fprofile-generate): every basic block and branch gets a counter. function size call-site count With profile data it can override those heuristics: a call site executed millions of times gets inlined even if it looks “too expensive” by static cost rules, because the runtime benefit clearly outweighs the code-size cost. continue straight to the next instruction Continuing straight is basically free; the CPU is already fetching instructions in order, so there’s no extra cost. the hot part stays in .text.hot The function still works identically (a jump connects them when needed), but now the hot part is smaller and denser, so more of it fits in an instruction-cache line, and cold code that’s almost never touched isn’t wasting icache space sitting next to it. 0
Subscribe Notify of new follow-up comments
Label {}
Name* Email* Website Δ
Label {}
Name* Email* Website Δ 0 Comments Oldest Newest
Resources RELATED POSTS October 16, 2026 | Zelmar Michelini “MongoDB was slow on Thursday”: answering the app team with mongo-health
PXC | October 16, 2026 | Przemysław Malkowski When a Small Change Writes Too Much – How A Linux Kernel Improvement Can Strike You in PXC/Galera Workloads
MySQL | October 15, 2026 | Marco Tusa JavaScript in MySQL: Extending SQL, Not Moving the Application
Far Enough. Said no pioneer ever. Get Started Open source database software from experts who stand with you in production. Forever free from lock-in and other corporate BS. Connect © 2026 Percona All Rights Reserved Database Technology PostgreSQL MySQL MariaDB MongoDB Valkey / Redis Databases on Kubernetes Monitoring & Management (PMM) Percona Toolkit Services Expert Support ExpertOps Expert Consulting Training Solution Bundles Subscription Policies Use Cases Cost Optimization Performance and Reliability Sovereignty, Security, and Compliance AI and Future Readiness Company About Percona Partners Careers Events Press Releases News Terms of Use | Privacy | Copyright | Legal | Security Center MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners. © 2026 Percona All Rights Reserved |
The discussion centers on the dilemma of implementing Profile-Guided Optimization (PGO), focusing on how it fundamentally reshapes compiled binaries rather than simply optimizing a specific workload. PGO is executed in a two-pass build process. The first pass involves compiling with instrumentation using the flag -fprofile-generate, which injects counters for every basic block and branch, accumulating execution counts for every path taken during a training workload. The second pass uses this collected profile data to drive advanced optimization decisions. This process is not aimed at making the training workload faster but rather at allowing the compiler to determine which parts of the code are hot and which are cold, enabling the compiler to restructure the entire binary accordingly. In the first phase of data collection, the instrumentation records finely grained counters for every edge in the control-flow graph, providing information on the frequency of execution for every branch, loop back-edge, and call site. This per-edge granularity is crucial, as it allows the subsequent phase to make surgical decisions based on actual execution patterns rather than aggregate function call counts. During the second phase, the compiler utilizes this profile data to perform several transformative optimizations. For function inlining, PGO can override static cost heuristics; a call site executed millions of times can be inlined even if it appears statically expensive, because the runtime benefit necessitates it. It prevents the inclusion of cold code in the binary, ensuring that only frequently executed paths are tightly integrated. Regarding branch layout, PGO guides the compiler to arrange the machine code such that the hot path serves as a straight line of execution, while cold paths are relocated and pushed out of line, often into separate sections of the binary. This strategy aims to eliminate pipeline bubbles caused by mispredictions, as the highly probable execution path flows continuously while unlikely alternatives are physically segregated. While source code ordering does not dictate machine code layout, the optimization ensures that the resulting binary layout significantly improves execution flow predictability. Hot and cold function splitting is also achieved by physically separating functions within the binary. A function may be split into a hot part residing in a highly cache-friendly section, such as .text.hot, and a rarely executed error-handling tail placed in a separate section, such as .text.unlikely. This segregation reduces the footprint of cold code, improving instruction cache locality for the dominant execution path. The concept of whole-binary function reordering becomes literal when leveraging Link-Time Optimization, which PGO facilitates. Functions that frequently execute sequentially during a hot workload are physically reordered in the final executable. This repositions frequently called functions to be adjacent in memory, which maximizes instruction cache and translation lookaside buffer locality by ensuring the CPU's fetch unit retrieves a tight cluster of relevant instructions rather than jumping across a large binary space. Further optimizations include indirect-call promotion, where if profile data indicates a virtual call or function pointer resolution overwhelmingly favors a single target, the compiler inserts a guarded direct call. This makes the branch predictor more efficient by favoring direct execution. Furthermore, trade-offs are managed between register allocation and code density. Hot code is compiled with aggressive unrolling and more dedicated registers, whereas cold code is compiled to minimize its physical footprint, as its runtime cost is irrelevant. PGO also influences switch and jump-table lowering by favoring the practical dominant case identified in the profile data, leading to more streamlined branching logic. Ultimately, the core principle is that PGO optimizes the physical layout of machine code—instruction adjacency, code section segregation, and call mechanisms—based solely on the shape of the control flow, which is exactly what is frequently exercised in production traffic. This optimization is effective regardless of whether the training data perfectly mirrors actual production traffic, as what matters is the distribution of control flow. |