Search-Based LLMs for Code Optimization
Preprint
Abstract
The code written by developers usually suffers from efficiency problems and contain various performance bugs. These inefficiencies necessitate the research of automated refactoring methods for code optimization. Early research in code optimization employs rule-based methods and focuses on specific inefficiency issues, which are labor-intensive and suffer from the low coverage issue. Recent work regards the task as a sequence generation problem, and resorts to deep learning (DL) techniques such as large language models (LLMs). These methods typically prompt LLMs to directly generate optimized code. Although these methods show state-of-the-art performance, such one-step generation paradigm is hard to achieve an optimal solution. First, complex optimization methods such as combinatorial ones are hard to be captured by LLMs. Second, the one-step generation paradigm poses challenge in precisely infusing the knowledge required for effective code optimization within LLMs, resulting in under-optimized code.To address these problems, we propose to model this task from the search perspective, and propose a search-based LLMs framework named SBLLM that enables iterative refinement and discovery of improved optimization methods. SBLLM synergistically integrate LLMs with evolutionary search and consists of three key components: 1) an execution-based representative sample selection part that evaluates the fitness of each existing optimized code and prioritizes promising ones to pilot the generation of improved code; 2) an adaptive optimization pattern retrieval part that infuses targeted optimization patterns into the model for guiding LLMs towards rectifying and progressively enhancing their optimization methods; and 3) a genetic operator-inspired chain-of-thought prompting part that aids LLMs in combining different optimization methods and generating improved optimization methods.Keywords
All Related Versions
This publication has 8 references indexed in Scilit:
- RAPGen: An Approach for Fixing Code Inefficiencies in Zero-Shot2025
- Supersonic: Learning to Generate Source Code Optimizations in C/C++IEEE Transactions on Software Engineering, 2024
- Lost in the Middle: How Language Models Use Long ContextsTransactions of the Association for Computational Linguistics, 2024
- Code Structure–Guided Transformer for Source Code SummarizationACM Transactions on Software Engineering and Methodology, 2023
- MORE: A multi‐objective refactoring recommendation approach to introducing design patterns and fixing code smellsJournal of Software: Evolution and Process, 2017
- Model refactoring using examples: a search‐based approachJournal of Software: Evolution and Process, 2014
- GenProg: A Generic Method for Automatic Software RepairIEEE Transactions on Software Engineering, 2011
- The Probabilistic Relevance Framework: BM25 and BeyondFoundations and Trends® in Information Retrieval, 2009