ReLOpt: A Retriever-Augmented Framework for Optimizing Code with Long-Range Dependencies
摘要
Code optimization is essential for improving application runtime performance, yet traditional methods rely heavily on expert-crafted rules, requiring substantial manual effort. While large language models (LLMs) have shown promise in various code-related tasks, their effectiveness in optimizing code with long-range dependencies remains limited. This is primarily due to the challenge of identifying scattered relevant code and the inherent complexity of code analysis. In this paper, we introduce ReLOpt, a novel framework that addresses these challenges by incorporating a Code Dependence-aware Retriever (CDR). The CDR enables distance-agnostic retrieval of relevant code segments and offers domain-specific optimization analysis as guidance. To evaluate ReLOpt, we construct OptiIR, a runnable code optimization dataset that includes input/output pairs for verifying the correctness of the model-optimized code. Experiments show that ReLOpt outperforms base models solely fine-tuned by OptiIR, achieving up to a 65.31% relative improvement in BLEU score. We release all of our code and data at https://github.com/ict-ql/ReLOpt .