BlogsUberGo Runtime Stack Optimization

Go Runtime Stack Optimization

Go Runtime Stack Optimization

2
posts
2026

Uber is actively optimizing the performance of its Go services, which constitute a significant portion of its infrastructure. This effort focuses on reducing CPU overhead by fine-tuning the Go runtime's stack allocation mechanisms and improving CPU resource allocation for containerized workloads. Initial work involved understanding and mitigating the costs associated with goroutine stack expansion, leading to the development of techniques to statically pre-allocate stack sizes and disable adaptive stack growth. This has resulted in significant CPU savings for specific services, with a plan to replicate these optimizations across more of Uber's Go services.

2026

Zero-Growth Stack, Real Gains: How Stack Allocation Can Save 10% CPU in Go

5/7/2026

This post details the technical approach to optimize Go runtime stack allocation by disabling adaptive stack growth and pre-allocating stack sizes. It describes the challenges with the default Go runtime behavior, explores alternative solutions like goroutine pooling, and dives into customizing the Go runtime via private linking to modify internal variables like `debug.adaptivestackstart` and `startingStackSize`. The post also outlines a profile-guided workflow for tuning stack sizes in production, including using the pprof library and disassembling binaries to determine function stack usage, leading to a 10% CPU improvement in a key service.

Hybrid Core Allocation: From Overallocation to Reliable Sharing

4/21/2026

This post introduces a significant evolution in Uber's CPU resource allocation strategy within its Odin container orchestration system. It details the transition from dedicated CPU allocation to a hybrid model that incorporates shared cores alongside dedicated ones. Key contributions include the introduction of shared core pooling, over-allocation control, fair contention handling via `cpu.shares`, and an upgraded vertical scaler. The post also discusses NUMA considerations for optimal CPU and memory affinity, the implementation of in-place vertical scaling for stateful workloads, and how Odin bridges Kubernetes gaps for hybrid core allocation. The core innovation is enabling more intelligent handling of bursty CPU usage patterns, leading to improved performance, reliability, and cost-effectiveness for colocated workloads.