Multi-Source and Cross-Scenario Strategy-Guided Code Optimization
Yuwei Zhao, Qianyu Xiao, Ye Cui, Yijun Yu, Yingfei Xiong
Abstract
Automated code optimization improves program performance by refactoring source code, and recent studies use LLMs to generate optimization patches. The newest approaches are strategy-guided: they summarize strategies from historical optimization commits as static analysis rules, and use these rules to match code locations for LLMs to optimize. However, these approaches have two limitations: (1) the strategies may come from other knowledge sources, such as textbooks and web pages, but the existing approaches cannot utilize them; (2) a strategy may be applicable to different scenarios, e.g., different programming languages, but existing approaches can only formalize strategies for the scenario to which the source commit belongs. To address these limitations, we propose MoST, an LLM-based code optimization framework that integrates multiple knowledge sources across scenarios. MoST uniformly represents items in different knowledge sources as evidence objects, clusters them in a cross-source and cross-scenario manner to identify strategies, and transfers them to the target scenario when necessary for generating static analysis rules. To implement this process, MoST employs a novel self-balanced weighted clustering algorithm to balance evidence objects from different knowledge sources, and a novel example transfer procedure to ensure the quality of the generated rules when transferring across scenarios. On a benchmark containing 151 C/C++, 150 Python, and 50 Rust historical optimization tasks, compared with SemOpt, MoST yields 24.44%-180.00% and 21.88%-37.50% more patches that are exactly the same as or semantically equivalent to developer patches, respectively. When optimizing 15 real-world projects, MoST achieves 19.72%-717.42% maximum improvements and 4.44%-258.17% average improvements for the performance tests in the projects, significantly outperforming SemOpt and Codex.
Create a lesson
Related papers
Measuring and Optimizing Energy Efficiency in ICT: A Multi-vocal Literature Review on Data Centers, Cloud Computing, and LLM-Driven Code Optimization
Shared title terminology · Tobias Böhm, Benjamin Weigell, Ezgi Sarikayak et al.
Multi-level Code Optimization via Mixture of Prompts
Shared title terminology · Yun Peng, Jun Wan, Jiakun Liu et al.
ATLAS: Multi-View Code Representation Tool for C and C++ Source Programs
Shared title terminology · Jaid Monwar Chowdhury, Ahmad Farhan Shahriar Chowdhury, Humayra Binte Monwar et al.
Pixels for Programs? A Cross-Provider Case Study of Input-Token Accounting for Source Code as Text and Images
Shared title terminology · Ronak Bhalgami
PerfAgent: Profiler-Guided Iterative Refinement for Repository-Level Code Optimization
Shared title terminology · Ryan Deng, Yuanzhe Liu, Bastian Lipka et al.
What Should an LLM Know? Knowledge-Guided Warm Starts for Software Optimization
Shared title terminology · Srinath Srinivasan, Tim Menzies