NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SWE-Perf: Can Language Models Optimize Code Performance on Real-World Repositories?

Xinyi He, Qian Liu, Mingzhe Du, Lin Yan, ZhiJie Fan, Yiming Huang, Yin Zheng, Zejian Yuan, Zejun Ma

Introduction

In modern software engineering, ensuring that code "works" is only the first step; ensuring it runs efficiently is critical for production-level systems. While existing benchmarks like SWE-Bench rigorously evaluate Large Language Models (LLMs) on their ability to fix bugs and generate functionally correct code, their capacity to optimize code performance at the repository level has remained largely unexplored.

Real-world performance bottlenecks are rarely confined to isolated, algorithmic functions. Instead, they involve complex module interactions, dataflow refactoring, and cross-file dependencies. To address this gap, researchers have introduced SWE-Perf, the first benchmark specifically designed to systematically evaluate LLMs on code performance optimization tasks within authentic repository contexts.

The SWE-Perf Benchmark

SWE-Perf shifts the focus from simple correctness to the open-ended challenge of performance optimization. The benchmark comprises 140 carefully curated instances drawn from nine major open-source Python projects, including scikit-learn, xarray, astropy, and sympy.

To build a rigorous test suite from real-world GitHub history, the researchers developed a robust pipeline:

  1. Mining and Filtering: The team analyzed over 100,000 Pull Requests (PRs) from popular Python repositories, isolating those that explicitly claimed to improve performance.
  2. Statistical Rigor: Performance testing is notoriously noisy. To separate genuine algorithmic improvements from environmental noise (e.g., background CPU processes), every test was executed 20 times in isolated Docker containers. Outliers were removed, and the Mann-Whitney U test was applied to ensure speedups were statistically significant.
  3. Comprehensive Context: Each benchmark instance includes the relevant codebase, target functions, performance-related tests, executable environments, and the original expert-authored patch to serve as a gold standard.

Evaluation Modes

The benchmark tests models under two distinct settings:

  • Oracle (File-Level): The model is provided with the specific files and functions that require optimization, testing its raw ability to refactor known bottlenecks.
  • Realistic (Repo-Level): The model acts as an autonomous agent (using frameworks like OpenHands or Agentless), tasked with navigating the entire repository to identify, diagnose, and resolve performance issues.

Key Findings: The Capability Gap

The evaluation of representative LLMs and agentic frameworks reveals a massive "capability gap" between current AI models and human experts.

  • Expert vs. AI Performance: Human-authored patches achieved an average performance gain of 10.85%. In contrast, the best-performing AI setup (OpenHands utilizing Claude-3.7-Sonnet) achieved only a 2.26% gain.
  • Correctness vs. Speed: Optimization often comes at the cost of stability for LLMs. Many models "optimized" code by inadvertently breaking its functionality. In the Realistic setting, even the top-performing models maintained functional correctness only about 77% of the time.
  • The Complexity Wall: As the number of target functions involved in a bottleneck increases, LLM performance drops sharply. While human experts can juggle the complexity of multi-function, repository-wide optimizations, LLMs currently struggle to maintain an accurate mental map of the broader system.
  • High-Level vs. Low-Level Focus: Keyword analysis highlighted a stark difference in optimization strategies. Human experts tend to focus on high-level abstractions (e.g., types, data structures, and data integrity), whereas LLMs frequently get bogged down in low-level infrastructure and boilerplate code.
  • Agents Outperform Prompts: Agent-based approaches significantly outperformed simple "one-shot" prompting. The ability to iteratively search the repository, apply patches, and run tests is crucial for tackling open-ended performance tasks.

Limitations and Future Directions

While SWE-Perf establishes a critical baseline, the authors acknowledge several limitations that pave the way for future research:

  • Language Scope: The current iteration of SWE-Perf is limited to Python. Expanding to languages where performance optimization is even more critical, such as C++ or Rust, is a logical next step.
  • The "Optimal" Ceiling: The benchmark relies on human patches as the ground truth. However, these human solutions may not represent the absolute optimal performance, leaving the "true" upper bound of potential improvement unknown.
  • Inference Costs: Deploying autonomous agents through thousands of iterations to achieve marginal speedups is computationally expensive, raising practical questions about the current return on investment for AI-driven optimization.

Ultimately, while LLMs have proven themselves as highly capable "coders," they are not yet reliable "performance engineers." SWE-Perf provides the essential scoreboard needed to track the AI community's progress as models learn to bridge this critical gap.

Summary updated

BibTeX
@inproceedings{he2026swe,
  author = {Xinyi He and Qian Liu and Mingzhe Du and Lin Yan and ZhiJie Fan and Yiming Huang and Yin Zheng and Zejian Yuan and Zejun MA},
  title = {{SWE-Perf: Can Language Models Optimize Code Performance on Real-World Repositories?}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=pNxw4i5Dp2},
}
Figure