[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"content:legacy:page:\u002Fposts\u002Fgolang\u002Foptimizing-performance-with-pgo":3,"content:legacy:navigation":223,"content:legacy:surround:\u002Fposts\u002Fgolang\u002Foptimizing-performance-with-pgo":508,"content:related-articles:Optimizing Performance in Go Applications with PGO":511},{"id":4,"title":5,"aside":6,"body":7,"categories":6,"category":207,"description":208,"duration":209,"extension":210,"footer":6,"header":6,"icon":6,"image":211,"main":6,"meta":214,"navigation":6,"path":215,"publishedAt":216,"seo":217,"sitemap":218,"stem":219,"tags":220,"toc":6,"top":221,"__hash__":222},"content\u002Fposts\u002Fgolang\u002Foptimizing-performance-with-pgo.md","Optimizing Performance in Go Applications with PGO",null,{"type":8,"value":9,"toc":200},"minimark",[10,15,19,22,35,39,46,49,85,88,93,96,117,120,125,128,143,146,150,153,164,167,171,196],[11,12,14],"h2",{"id":13},"introduction","🚀 Introduction",[16,17,18],"p",{},"Profile-Guided Optimization (PGO) is a powerful feature introduced in Go 1.21 that allows developers to optimize their applications based on real-world usage patterns. By collecting utilizing profiling data during the execution of your application, PGO can help the Go compiler make better decisions about inlining, loop unrolling, and other optimizations, leading to improved performance and reduced resource consumption. . PGO collects information about how the application actually runs, then uses that data to improve performance when recompiled.",[16,20,21],{},"Benefits of PGO in Golang:",[23,24,25,29,32],"ul",{},[26,27,28],"li",{},"Improve program execution speed.",[26,30,31],{},"Reduce system resource consumption.",[26,33,34],{},"Optimize important code parts based on how the application actually operates.",[11,36,38],{"id":37},"️-implementation-steps","🛠️ Implementation Steps",[16,40,41,45],{},[42,43,44],"strong",{},"1. Collect Profile data",":",[16,47,48],{},"Run the application with the -test.cpuprofile flag to create a CPU profile:",[50,51,56],"pre",{"className":52,"code":53,"language":54,"meta":55,"style":55},"language-bash shiki shiki-themes github-light github-dark","go test -cpuprofile cpu.prof -bench .\n","bash","",[57,58,59],"code",{"__ignoreMap":55},[60,61,64,68,72,76,79,82],"span",{"class":62,"line":63},"line",1,[60,65,67],{"class":66},"sScJk","go",[60,69,71],{"class":70},"sZZnC"," test",[60,73,75],{"class":74},"sj4cs"," -cpuprofile",[60,77,78],{"class":70}," cpu.prof",[60,80,81],{"class":74}," -bench",[60,83,84],{"class":70}," .\n",[16,86,87],{},"This command will collect actual performance data during the benchmark run and save it to the cpu.prof file.",[16,89,90,45],{},[42,91,92],{},"2. Recompile with PGO",[16,94,95],{},"After having the profile data, compile the application with the -pgo flag to use the optimized data:",[50,97,99],{"className":52,"code":98,"language":54,"meta":55,"style":55},"go build -pgo=cpu.prof -o myapp\n",[57,100,101],{"__ignoreMap":55},[60,102,103,105,108,111,114],{"class":62,"line":63},[60,104,67],{"class":66},[60,106,107],{"class":70}," build",[60,109,110],{"class":74}," -pgo=cpu.prof",[60,112,113],{"class":74}," -o",[60,115,116],{"class":70}," myapp\n",[16,118,119],{},"At this point, Go will rely on the profile data to optimize important parts of the application.",[16,121,122,45],{},[42,123,124],{},"3. Run the Application",[16,126,127],{},"Run the application and compare the performance before and after optimization using the benchmark tool:",[50,129,131],{"className":52,"code":130,"language":54,"meta":55,"style":55},"go test -bench .\n",[57,132,133],{"__ignoreMap":55},[60,134,135,137,139,141],{"class":62,"line":63},[60,136,67],{"class":66},[60,138,71],{"class":70},[60,140,81],{"class":74},[60,142,84],{"class":70},[16,144,145],{},"If PGO works effectively, you will see the application running faster and using less resources! 🚀",[11,147,149],{"id":148},"when-to-use-pgo","🔔 When to use PGO?",[16,151,152],{},"PGO is especially useful when:",[23,154,155,158,161],{},[26,156,157],{},"The application has frequently running functions that need to be optimized.",[26,159,160],{},"The application needs to make the most of hardware resources.",[26,162,163],{},"You want to improve performance without editing code.",[16,165,166],{},"As you develop your Go applications, consider integrating PGO into your build process to take advantage of these performance benefits",[11,168,170],{"id":169},"additional-resources","📚 Additional Resources",[23,172,173,182,189],{},[26,174,175],{},[176,177,181],"a",{"href":178,"rel":179},"https:\u002F\u002Fgolang.org\u002Fdoc\u002Fgo1.21#pgo",[180],"nofollow","Go 1.21 Release Notes",[26,183,184],{},[176,185,188],{"href":186,"rel":187},"https:\u002F\u002Fgolang.org\u002Fpkg\u002Fruntime\u002Fpprof\u002F",[180],"Go Profiling Documentation",[26,190,191],{},[176,192,195],{"href":193,"rel":194},"https:\u002F\u002Fblog.golang.org\u002Fpgo",[180],"Profile-Guided Optimization in Go",[197,198,199],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":55,"searchDepth":201,"depth":201,"links":202},2,[203,204,205,206],{"id":13,"depth":201,"text":14},{"id":37,"depth":201,"text":38},{"id":148,"depth":201,"text":149},{"id":169,"depth":201,"text":170},"golang","How to use Profile-Guided Optimization (PGO) to improve your application's performance.",3,"md",{"src":212,"alt":213},"https:\u002F\u002Fraw.githubusercontent.com\u002Ffullstack-core\u002Fblog\u002Frefs\u002Fheads\u002Fmain\u002Fblog\u002Fcover\u002Foptimizing-performance-in-go-with-pgo.jpg","PGO_image",{},"\u002Fposts\u002Fgolang\u002Foptimizing-performance-with-pgo","2025-06-14",{"title":5,"description":208},{"loc":215,"lastmod":216},"posts\u002Fgolang\u002Foptimizing-performance-with-pgo",[207],false,"x3JnYuH2WIQGjyMm1nZgKtcRAmZ4LEc5JjfZhB71kl8",[224,340,348,487],{"title":225,"icon":226,"path":227,"stem":228,"children":229,"page":221},"Cheatsheets","fluent-color:paw-16","\u002Fcheatsheets","cheatsheets",[230,235,240,245,250,255,260,265,270,275,280,285,290,295,300,305,310,315,320,325,330,335],{"title":231,"path":232,"stem":233,"icon":234},"Bash","\u002Fcheatsheets\u002Fbash","cheatsheets\u002Fbash","material-icon-theme:powershell",{"title":236,"path":237,"stem":238,"icon":239},"CSS","\u002Fcheatsheets\u002Fcss","cheatsheets\u002Fcss","vscode-icons:file-type-css2",{"title":241,"path":242,"stem":243,"icon":244},"Docker","\u002Fcheatsheets\u002Fdocker","cheatsheets\u002Fdocker","vscode-icons:file-type-docker2",{"title":246,"path":247,"stem":248,"icon":249},"Git","\u002Fcheatsheets\u002Fgit","cheatsheets\u002Fgit","devicon:git",{"title":251,"path":252,"stem":253,"icon":254},"Golang","\u002Fcheatsheets\u002Fgo","cheatsheets\u002Fgo","material-icon-theme:go",{"title":256,"path":257,"stem":258,"icon":259},"HTML","\u002Fcheatsheets\u002Fhtml","cheatsheets\u002Fhtml","material-icon-theme:html",{"title":261,"path":262,"stem":263,"icon":264},"JavaScript","\u002Fcheatsheets\u002Fjavascript","cheatsheets\u002Fjavascript","material-icon-theme:javascript",{"title":266,"path":267,"stem":268,"icon":269},"Latex","\u002Fcheatsheets\u002Flatex","cheatsheets\u002Flatex","material-icon-theme:latexmk",{"title":271,"path":272,"stem":273,"icon":274},"Linux","\u002Fcheatsheets\u002Flinux","cheatsheets\u002Flinux","devicon:linux",{"title":276,"path":277,"stem":278,"icon":279},"Markdown","\u002Fcheatsheets\u002Fmarkdown","cheatsheets\u002Fmarkdown","material-icon-theme:markdown",{"title":281,"path":282,"stem":283,"icon":284},"Mongo","\u002Fcheatsheets\u002Fmongo","cheatsheets\u002Fmongo","devicon:mongodb",{"title":286,"path":287,"stem":288,"icon":289},"Nest","\u002Fcheatsheets\u002Fnest","cheatsheets\u002Fnest","material-icon-theme:nest",{"title":291,"path":292,"stem":293,"icon":294},"Next","\u002Fcheatsheets\u002Fnext","cheatsheets\u002Fnext","logos:nextjs-icon",{"title":296,"path":297,"stem":298,"icon":299},"Node","\u002Fcheatsheets\u002Fnode","cheatsheets\u002Fnode","material-icon-theme:nodejs",{"title":301,"path":302,"stem":303,"icon":304},"Nuxt","\u002Fcheatsheets\u002Fnuxt","cheatsheets\u002Fnuxt","material-icon-theme:nuxt",{"title":306,"path":307,"stem":308,"icon":309},"React","\u002Fcheatsheets\u002Freact","cheatsheets\u002Freact","material-icon-theme:react",{"title":311,"path":312,"stem":313,"icon":314},"Redis","\u002Fcheatsheets\u002Fredis","cheatsheets\u002Fredis","vscode-icons:folder-type-redis-opened",{"title":316,"path":317,"stem":318,"icon":319},"SQL","\u002Fcheatsheets\u002Fsql","cheatsheets\u002Fsql","material-icon-theme:database",{"title":321,"path":322,"stem":323,"icon":324},"Typescript","\u002Fcheatsheets\u002Ftypescript","cheatsheets\u002Ftypescript","material-icon-theme:typescript",{"title":326,"path":327,"stem":328,"icon":329},"Vercel","\u002Fcheatsheets\u002Fvercel","cheatsheets\u002Fvercel","vscode-icons:file-type-light-vercel",{"title":331,"path":332,"stem":333,"icon":334},"Vue","\u002Fcheatsheets\u002Fvue","cheatsheets\u002Fvue","material-icon-theme:vue",{"title":336,"path":337,"stem":338,"icon":339},"Windows","\u002Fcheatsheets\u002Fwindow","cheatsheets\u002Fwindow","material-icon-theme:folder-windows",{"title":341,"icon":226,"path":342,"stem":343,"children":344,"page":221},"Interviews","\u002Finterviews","interviews",[345],{"title":256,"path":346,"stem":347,"icon":259},"\u002Finterviews\u002Fhtml","interviews\u002Fhtml",{"title":349,"icon":350,"path":351,"stem":352,"children":353,"page":221},"Posts","fluent-color:data-bar-vertical-ascending-24","\u002Fposts","posts",[354,363,379,405,410,423,432,441,451,477],{"title":355,"icon":319,"redirect":356,"path":357,"stem":358,"children":359,"page":221},"Database","\u002Fposts\u002Fdatabase\u002Freplication-strategy","\u002Fposts\u002Fdatabase","posts\u002Fdatabase",[360],{"title":361,"path":356,"stem":362,"icon":6},"Database Replication strategy in large systems","posts\u002Fdatabase\u002Freplication-strategy",{"title":241,"icon":244,"redirect":364,"path":365,"stem":366,"children":367,"page":221},"\u002Fposts\u002Fdocker\u002Fdocker-commands","\u002Fposts\u002Fdocker","posts\u002Fdocker",[368,371,375],{"title":369,"path":364,"stem":370,"icon":6},"Docker commands essentials","posts\u002Fdocker\u002Fdocker-commands",{"title":372,"path":373,"stem":374,"icon":6},"Some useful Dockerfile templates","\u002Fposts\u002Fdocker\u002Fdockerfile-templates","posts\u002Fdocker\u002Fdockerfile-templates",{"title":376,"path":377,"stem":378,"icon":6},"Setup Docker environment on Windows","\u002Fposts\u002Fdocker\u002Fsetup-docker-on-window","posts\u002Fdocker\u002Fsetup-docker-on-window",{"title":380,"icon":381,"redirect":382,"path":383,"stem":384,"children":385,"page":221},"Git & GitHub","material-icon-theme:git","\u002Fposts\u002Fgit\u002Fbrightly-decorate-graph","\u002Fposts\u002Fgit","posts\u002Fgit",[386,389,393,397,401],{"title":387,"path":382,"stem":388,"icon":6},"Brightly decorate your GitHub Graph","posts\u002Fgit\u002Fbrightly-decorate-graph",{"title":390,"path":391,"stem":392,"icon":6},"Download a specific folder on GitHub repository","\u002Fposts\u002Fgit\u002Fdownload-specific-folder","posts\u002Fgit\u002Fdownload-specific-folder",{"title":394,"path":395,"stem":396,"icon":6},"Syncing Git Tags across to other repositories","\u002Fposts\u002Fgit\u002Fsyncing-tags-across-repositories","posts\u002Fgit\u002Fsyncing-tags-across-repositories",{"title":398,"path":399,"stem":400,"icon":6},"Unlocking GitHub Achievement badges","\u002Fposts\u002Fgit\u002Funlocking-achievement-badges","posts\u002Fgit\u002Funlocking-achievement-badges",{"title":402,"path":403,"stem":404,"icon":6},"Essential Git commands every developer should master","\u002Fposts\u002Fgit\u002Fuseful-commands-like-pro","posts\u002Fgit\u002Fuseful-commands-like-pro",{"title":251,"icon":254,"redirect":215,"path":406,"stem":407,"children":408,"page":221},"\u002Fposts\u002Fgolang","posts\u002Fgolang",[409],{"title":5,"path":215,"stem":219,"icon":6},{"title":261,"icon":411,"redirect":412,"path":413,"stem":414,"children":415,"page":221},"vscode-icons:file-type-js","\u002Fposts\u002Fjavascript\u002F9-lines-of-tips","\u002Fposts\u002Fjavascript","posts\u002Fjavascript",[416,419],{"title":417,"path":412,"stem":418,"icon":6},"9 lines of JavaScript replace 50 lines of code","posts\u002Fjavascript\u002F9-lines-of-tips",{"title":420,"path":421,"stem":422,"icon":6},"Javascript Promises - Specific functions and use cases","\u002Fposts\u002Fjavascript\u002Fpromises-cheatsheet","posts\u002Fjavascript\u002Fpromises-cheatsheet",{"title":296,"icon":424,"redirect":425,"path":426,"stem":427,"children":428,"page":221},"material-icon-theme:nodejs-alt","\u002Fposts\u002Fnodejs\u002Fevent-loop","\u002Fposts\u002Fnodejs","posts\u002Fnodejs",[429],{"title":430,"path":425,"stem":431,"icon":6},"Secret about Event Loop flow in Nodejs","posts\u002Fnodejs\u002Fevent-loop",{"title":301,"icon":433,"redirect":434,"path":435,"stem":436,"children":437,"page":221},"vscode-icons:file-type-nuxt","\u002Fposts\u002Fnuxt\u002Fenable-pwa-in-nuxt","\u002Fposts\u002Fnuxt","posts\u002Fnuxt",[438],{"title":439,"path":434,"stem":440,"icon":6},"Enable PWA and Service Worker in Nuxt","posts\u002Fnuxt\u002Fenable-pwa-in-nuxt",{"title":442,"icon":443,"redirect":444,"path":445,"stem":446,"children":447,"page":221},"Performance","emojione:rocket","\u002Fposts\u002Fperformance\u002Fbackground-image-injection-problem","\u002Fposts\u002Fperformance","posts\u002Fperformance",[448],{"title":449,"path":444,"stem":450,"icon":6},"Background-Image injection problem in UX","posts\u002Fperformance\u002Fbackground-image-injection-problem",{"title":452,"icon":453,"redirect":454,"path":455,"stem":456,"children":457,"page":221},"Tutorial","fluent-color:book-open-lightbulb-24","\u002Fposts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers","\u002Fposts\u002Ftutorial","posts\u002Ftutorial",[458,461,465,469,473],{"title":459,"path":454,"stem":460,"icon":6},"Classification and functionality of the servers","posts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers",{"title":462,"path":463,"stem":464,"icon":6},"What is the difference between localhost and 127.0.0.1?","\u002Fposts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1","posts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1",{"title":466,"path":467,"stem":468,"icon":6},"8 essential network protocols every programmer should know","\u002Fposts\u002Ftutorial\u002Fessential-network-protocols","posts\u002Ftutorial\u002Fessential-network-protocols",{"title":470,"path":471,"stem":472,"icon":6},"Pre rels in header link tag - SEO technique enhancement","\u002Fposts\u002Ftutorial\u002Fpre-rels-in-header-link-tag","posts\u002Ftutorial\u002Fpre-rels-in-header-link-tag",{"title":474,"path":475,"stem":476,"icon":6},"Better code with SOLID principles","\u002Fposts\u002Ftutorial\u002Fwhat-is-solid","posts\u002Ftutorial\u002Fwhat-is-solid",{"title":478,"icon":479,"redirect":480,"path":481,"stem":482,"children":483,"page":221},"UI\u002FUX","devicon:figma","\u002Fposts\u002Fuiux\u002Fcommon-button-mistake","\u002Fposts\u002Fuiux","posts\u002Fuiux",[484],{"title":485,"path":480,"stem":486,"icon":6},"Common Button Mistake in UI\u002FUX","posts\u002Fuiux\u002Fcommon-button-mistake",{"title":488,"icon":489,"path":490,"stem":491,"children":492,"page":221},"Templates","fluent-color:data-pie-24","\u002Ftemplates","templates",[493,496,499,502,505],{"title":251,"path":494,"stem":495,"icon":254},"\u002Ftemplates\u002Fgo","templates\u002Fgo",{"title":291,"path":497,"stem":498,"icon":294},"\u002Ftemplates\u002Fnext","templates\u002Fnext",{"title":301,"path":500,"stem":501,"icon":304},"\u002Ftemplates\u002Fnuxt","templates\u002Fnuxt",{"title":306,"path":503,"stem":504,"icon":309},"\u002Ftemplates\u002Freact","templates\u002Freact",{"title":331,"path":506,"stem":507,"icon":334},"\u002Ftemplates\u002Fvue","templates\u002Fvue",[509,510],{"title":402,"path":403,"stem":404,"children":-1},{"title":417,"path":412,"stem":418,"children":-1},[]]