PerfAgent: Profiler-Guided Iterative Refinement for Repository-Level Code Optimization

· Source: cs.SE updates on arXiv.org · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Expert, extended

Summary

PerfAgent is a profiler-guided, verifier-in-the-loop workflow designed to enhance large language model (LLM) agents for repository-level code optimization. It addresses three key LLM failure modes: missing real bottlenecks, premature termination after shallow speedups, and insufficient testing. PerfAgent feeds agents curated profiler summaries, employs an objective-driven loop controller that retains the fastest correct patch across up to 5 iterations, and uses selective validation via pytest-testmon to catch regressions efficiently. On two challenging optimization benchmarks, GSO and SWE-fficiency-Lite, PerfAgent more than doubles the rate of expert-matching patches over OpenHands with GPT-5.1, improving from 19.6% to 39.2% on GSO and from 26% to 74% on SWE-fficiency-Lite. It also surpasses an oracle best-of-five baseline at substantially lower cost.

Key takeaway

For AI Engineers tasked with optimizing large codebases using LLM agents, you should integrate profiler-guided, iterative refinement workflows like PerfAgent. This approach helps your agents move beyond superficial speedups and identify deep, cross-abstraction bottlenecks, leading to expert-level performance gains. By adopting selective testing and an objective-driven loop, you can ensure both significant speedups and robust correctness, avoiding costly regressions and premature termination.

Key insights

Profiler-guided, iterative feedback enables LLM agents to achieve expert-level repository-wide code optimization.

Principles

Method

PerfAgent uses py-spy for curated hotspot summaries, an objective-driven loop with up to 5 iterations to retain the fastest correct patch, and pytest-testmon for selective validation.

In practice

Topics

Code references

Best for: Research Scientist, AI Scientist, Machine Learning Engineer, AI Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by cs.SE updates on arXiv.org.