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 ~39% of them verbatim, in an expert-verified dataset of past performance changes made by C# developers.
翻译:性能缺陷是一类非功能性缺陷,即使在经过充分测试的商业产品中也可能出现。修复这类性能缺陷是一个重要且具有挑战性的问题。本文针对这一挑战,提出了一种名为检索增强提示生成(RAPGen)的新方法。对于存在性能问题的代码片段,RAPGen首先从预构建的历史性能缺陷修复知识库中检索提示指令,然后基于检索到的指令生成提示信息。接着,该方法将此提示应用于大型语言模型(如Codex)进行零样本修复。我们将所提方法与多种提示变体及性能缺陷修复领域的最新方法进行了比较。实验评估表明,在经C#开发者先前性能修改验证的专家数据集中,RAPGen在约60%的案例中能生成与开发者相当或更优的性能改进建议,其中约39%的修复建议与开发者原方案完全一致。