Skip to main navigation Skip to search Skip to main content

Search-Based LLMs for Code Optimization

  • Shuzheng Gao
  • , Cuiyun Gao*
  • , Wenchao Gu
  • , Michael R. Lyu
  • *Corresponding author for this work
  • Chinese University of Hong Kong
  • School of Computer Science and Technology, Harbin Institute of Technology
  • Peng Cheng Laboratory

Research output: Chapter in Book/Report/Conference proceedingConference contributionpeer-review

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 operatorinspired chain-of-thought prompting part that aids LLMs in combining different optimization methods and generating improved optimization methods. Our evaluation of SBLLM on a dataset of Python and C++ code demonstrates its effectiveness in improving code efficiency. Specifically, the results indicate that SBLLM can improve program execution efficiency by up to 209.59% and consistently outperform all baseline methods by 8.75% ∼ 28.06 % and 1.15% ∼ 9.56 % with different LLMs in terms of top-5 speedup rate on Python and C++, respectively.

Original languageEnglish
Title of host publicationProceedings - 2025 IEEE/ACM 47th International Conference on Software Engineering, ICSE 2025
PublisherIEEE Computer Society
Pages578-590
Number of pages13
ISBN (Electronic)9798331505691
DOIs
StatePublished - 2025
Externally publishedYes
Event47th IEEE/ACM International Conference on Software Engineering, ICSE 2025 - Ottawa, Canada
Duration: 27 Apr 20253 May 2025

Publication series

NameProceedings - International Conference on Software Engineering
ISSN (Print)0270-5257

Conference

Conference47th IEEE/ACM International Conference on Software Engineering, ICSE 2025
Country/TerritoryCanada
CityOttawa
Period27/04/253/05/25

UN SDGs

This output contributes to the following UN Sustainable Development Goals (SDGs)

  1. SDG 3 - Good Health and Well-being
    SDG 3 Good Health and Well-being

Fingerprint

Dive into the research topics of 'Search-Based LLMs for Code Optimization'. Together they form a unique fingerprint.

Cite this