Technology

Go Stack Allocation Boosts Uber CPU Efficiency

Uber engineers optimized Go stack allocation, cutting CPU usage by up to 10% in critical services through static pre-allocation and disabling dynamic growth.

Daniel Singer

By Daniel Singer, Editor, StartupHub.ai

3 min read

Abstract visualization of data flow and CPU processes, representing Go stack allocation optimization.
Visualizing the impact of Go stack allocation tuning on CPU performance.Credit: Uber Engineering
Visual TL;DR
Go Stack ExpansionDriver
goroutines dynamically doubling stack size and copying data
From the article 9+ mentionsAt Uber's scale, where 1% efficiency gains equate to millions of dollars, minimizing this 'stack expansion' is paramount.
CPU UsageDriver
repeated stack growth consumes significant CPU cycles at scale
From the article 9 mentionsThe ride-sharing giant has detailed how tweaking Go's stack allocation mechanisms slashed CPU usage by as much as 10% in key services, translating to significant operational cost reductions across millions of cores.
Uber's Go DeploymentCore
massive scale where efficiency gains mean millions of dollars
From the article 7 mentionsUber is squeezing more performance out of its massive Go deployment.
Static Pre-allocationCore
disabling dynamic stack growth for critical services
From the articleBy disabling Go's adaptive stack sizing and stack shrinking features, and then pre-allocating goroutine stacks to a static, larger size, they aimed to eliminate the costly dynamic expansion process.
Granular OptimizationsContext
From the article 2 mentionsThis breakthrough, reported by Uber Engineering, underscores the critical role of granular optimizations for large-scale cloud infrastructure.
Tuning RuntimeCore
optimizing Go's stack allocation mechanisms for performance
From the article 6 mentionsThis effort highlights how even mature platforms like Go can benefit from deep, specialized tuning for extreme scale.
CPU Efficiency BoostEffect
cutting CPU usage by up to 10% in key services
From the articleThis focus on CPU efficiency in Go services is reminiscent of other efforts, such as mimalloc: Microsoft's Speed Boost for Apps.
Cost ReductionOutcome
From the article 2 mentionsThe ride-sharing giant has detailed how tweaking Go's stack allocation mechanisms slashed CPU usage by as much as 10% in key services, translating to significant operational cost reductions across millions of cores.
Contents(3)

Uber is squeezing more performance out of its massive Go deployment. The ride-sharing giant has detailed how tweaking Go's stack allocation mechanisms slashed CPU usage by as much as 10% in key services, translating to significant operational cost reductions across millions of cores. This breakthrough, reported by Uber Engineering, underscores the critical role of granular optimizations for large-scale cloud infrastructure.

Go’s runtime, designed for efficiency, uses goroutines which have much smaller initial stack sizes (2KB) compared to OS threads (2MB). When a goroutine's stack fills up, Go dynamically doubles its size and copies the data, a process that consumes CPU cycles. At Uber's scale, where 1% efficiency gains equate to millions of dollars, minimizing this 'stack expansion' is paramount.

The Stack Expansion Problem

While Go 1.19 introduced adaptive stack sizing to improve initial allocation, it wasn't enough for all workloads. Uber found that repeated stack growth remained a significant CPU drain in some services.

One service, in particular, showed nearly 10% of its CPU consumption attributed to stack growth, despite having ample memory available.

Tuning the Runtime

Uber explored two main paths: goroutine pooling and customizing the Go runtime. Goroutine pooling requires substantial code changes and introduces its own overhead. Instead, Uber opted to modify the Go runtime directly.

The daily brief

Get the free daily brief with the day's AI news, new AI startups and funding rounds every morning.

Join 11,990 subscribers.

By disabling Go's adaptive stack sizing and stack shrinking features, and then pre-allocating goroutine stacks to a static, larger size, they aimed to eliminate the costly dynamic expansion process. This involved patching the Go source code to expose and control internal variables related to stack size.

The team developed an analysis tool that inspects Go binaries to determine the actual stack usage of functions. This allowed them to statically set optimal stack sizes, preventing runtime overrides and minimizing the performance impact.

Impact and Future

The results were dramatic. One service saw its stack growth CPU cost drop from nearly 10% to under 1% after increasing the stack size from the default 2KB to 32KB. Memory usage increased, but remained well within container limits.

Uber plans to expand this optimization across more services, focusing on those with high CPU usage from stack growth and relatively low memory footprints. This approach, while requiring internal runtime modifications, demonstrates the potential for significant gains by optimizing core language features for specific operational demands.

This effort highlights how even mature platforms like Go can benefit from deep, specialized tuning for extreme scale. This focus on CPU efficiency in Go services is reminiscent of other efforts, such as mimalloc: Microsoft's Speed Boost for Apps.

Mentioned in this story

Markets

Sources

Get the free daily brief every morning

Every morning the day's AI news, new AI startups and new funding rounds. Free and takes a few minutes to read, unsubscribe at any time.

Join 11,990 subscribers.

TopicsGoProgrammingBackendEngineeringOptimizationUberCloud ComputingPerformance

Daniel Singer

Written by

Daniel Singer

Editor, StartupHub.ai

Daniel Singer is the editor of StartupHub.ai, a technology expert and thought leader on AI and its applications across sectors, from fintech and healthcare to developer tooling and consumer software. He writes and tests the tools covered here thoroughly and regularly, and built StartupHub.ai to give founders, operators and buyers a clearer read on what they are actually being sold.

Test your Agent Readiness now

Paste your website. How well ChatGPT, Claude and the other agents can read and use a site, in about a minute, free.

Watch

The videos behind the news, one flip at a time

The feed mixes the videos from our articles with startup demos and you flip through them like TV channels for free with no signup.