Multi-Source and Cross-Scenario Strategy-Guided Code Optimization
2026-07-22 • Software Engineering
Software Engineering
AI summaryⓘ
The authors propose MoST, a tool that helps computers automatically improve code by learning from many knowledge sources like textbooks and web pages, not just past code changes. MoST groups similar ideas from these sources and applies them to different programming languages to create better rules for optimization. It uses new methods to balance and transfer knowledge across scenarios effectively. Testing shows MoST finds more useful code improvements and boosts program performance better than previous tools. Overall, the authors show that combining diverse knowledge helps optimize code more accurately and broadly.
automated code optimizationlarge language models (LLMs)static analysis rulescode refactoringknowledge transferclustering algorithmsprogram performancecross-scenario optimizationsource code patchesprogramming languages
Authors
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.