ECO: An LLM-Driven Efficient Code Optimizer for Warehouse Scale Computers

Hannah Lin, Martin Maas, Maximilian Roquemore, Arman Hasanzadeh, Fred Lewis, Yusuf Simonson, Tzu-Wei Yang, Amir Yazdanbakhsh, Deniz Altinbüken, Florin Papa, Maggie Nolan Edmonds, Aditya Patil, Don Schwarz, Satish Chandra, Chris Kennelly, Milad Hashemi, Parthasarathy RanganathanarXiv 2025 · DOI

Abstract

As compute demands in hyperscale data centers outpace hardware improvements, software efficiency becomes paramount. We present ECO (Efficient Code Optimizer), a production-scale system at Google that leverages fine-tuned Large Language Models (LLMs) to automate semantic code refactoring. By mining historical performance fixes and utilizing vector similarity search combined with continuous profiling, ECO identifies and optimizes inefficient code patterns. To date, ECO has successfully landed over 6,400 commits, resulting in savings equivalent to 500,000 CPU cores per quarter with a 99.5% success rate.

Introduction

The slowing of Moore’s Law necessitates a shift toward software-level optimizations to manage the growing compute requirements of modern warehouse-scale computers. While traditional compilers excel at low-level optimizations, they often lack the semantic understanding required for higher-level refactoring, such as eliminating redundant data structure lookups or optimizing memory allocation strategies. Historically, these "semantic" optimizations have relied on manual effort by performance experts, a process that is unscalable for codebases comprising billions of lines. ECO addresses this challenge by automating the identification and remediation of performance anti-patterns at scale.

The ECO Pipeline

The ECO system operates through a multi-stage pipeline designed to discover, localize, and fix performance inefficiencies.

The ECO pipeline: from historical anti-pattern mining to code similarity search, candidate ranking, and final optimization.
  1. Opportunity Discovery: The process begins by mining decades of historical commits to identify recurring performance anti-patterns and their corresponding human-authored fixes.
  2. Localization: Using "Deep Code Embeddings" and vector similarity search (ScaNN), ECO identifies semantically similar code segments within the current repository.
  3. Candidate Ranking: To maximize impact, candidates are filtered using Google-Wide Profiling (GWP) data, prioritizing functions with high CPU consumption.
  4. Edit Generation and Validation: A fine-tuned Gemini Pro model generates optimized code edits, which then undergo rigorous automated and human verification.

LLM-Driven Refactoring and Verification

The core of ECO's generative capability lies in its use of specialized LLMs and a robust validation framework.

The LLM-driven workflow for edit generation, validation, and human-in-the-loop review.

ECO utilizes a fine-tuned version of Gemini Pro, employing advanced prompting techniques like Chain-of-Thought (CoT) and ReAct to navigate complex refactoring logic. To ensure production-grade reliability, the system incorporates a multi-stage validation process:

  • Automated builds and unit tests verify functional correctness.
  • LLM-based "self-review" identifies common coding pitfalls.
  • Human code review by domain owners provides a final safety check.
  • Post-deployment monitoring tracks performance to prevent regressions.

Datasets and Evaluation

ECO was developed using a newly curated dataset of approximately 55,000 historical performance-improving commits. This data, along with proprietary source code, was used to fine-tune Gemini Pro for C++ specific refactoring tasks. Evaluation was conducted using both synthetic microbenchmarks and a set of 48 real-world historical commits to ensure the model could accurately replicate expert human optimizations.

Key Results

ECO has demonstrated significant real-world impact at Google:

  • Scale of Impact: Over 6,400 commits submitted, affecting more than 25,000 lines of production code.
  • Resource Savings: Average savings of over 500,000 normalized CPU cores per quarter.
  • Reliability: A production success rate exceeding 99.5%, with rollbacks due to bugs or regressions being extremely rare (<0.5%).
  • Human Efficiency: Enables a small engineering team to drive fleet-wide efficiency gains that would otherwise require thousands of manual hours.

Conclusion and Future Work

ECO demonstrates the viability of using LLMs for large-scale, semantic code optimization in production environments. While currently reactive, future work aims to move toward proactive optimizations during the development process, expanding the scope to multi-file refactors and targeting other resource dimensions such as network and storage efficiency.

Summary updated

BibTeX
@misc{lin2025eco,
  author = {Hannah Lin and Martin Maas and Maximilian Roquemore and Arman Hasanzadeh and Fred Lewis and Yusuf Simonson and Tzu-Wei Yang and Amir Yazdanbakhsh and Deniz Altinbüken and Florin Papa and Maggie Nolan Edmonds and Aditya Patil and Don Schwarz and Satish Chandra and Chris Kennelly and Milad Hashemi and Parthasarathy Ranganathan},
  title = {{ECO: An LLM-Driven Efficient Code Optimizer for Warehouse Scale Computers}},
  year = {2025},
  eprint = {2503.15669},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.15669},
}
Figure