🤖 AI Summary
To address the challenge of zero-shot code performance bug fixing, this paper proposes a retrieval-augmented prompting method: it constructs a structured C# performance-fix knowledge base and employs semantic retrieval to match historical repair instructions, thereby generating zero-shot prompts that guide large language models (e.g., Codex) to directly produce efficient fixes. This work is the first to introduce the Retrieval-Augmented Generation (RAG) paradigm into zero-shot performance bug repair—requiring no fine-tuning, in-context examples, or manual prompt engineering, thus enabling plug-and-play transfer of expert knowledge. Evaluated on an expert-annotated C# performance benchmark, the method achieves developer-level repair quality in 60% of cases, with 42% yielding exact matches—significantly outperforming diverse prompting strategies and state-of-the-art baselines. The approach effectively bridges knowledge transfer and LLM-based code optimization.
📝 Abstract
Performance bugs are non-functional bugs that can even manifest in well-tested commercial products. Fixing these performance bugs is an important yet challenging problem. In this work, we address this challenge and present a new approach called Retrieval-Augmented Prompt Generation (RAPGen). Given a code snippet with a performance issue, RAPGen first retrieves a prompt instruction from a pre-constructed knowledge-base of previous performance bug fixes and then generates a prompt using the retrieved instruction. It then uses this prompt on a Large Language Model (such as Codex) in zero-shot to generate a fix. We compare our approach with the various prompt variations and state of the art methods in the task of performance bug fixing. Our evaluation shows that RAPGen can generate performance improvement suggestions equivalent or better than a developer in ~60% of the cases, getting ~42% of them verbatim, in an expert-verified dataset of past performance changes made by C# developers.