arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~

通过混合提示进行多级代码优化

Multi-level Code Optimization via Mixture of Prompts

Yun Peng, Jun Wan, Jiakun Liu, Shuzheng Gao, David Lo, Xiaoxue Ren

arXiv 2607.23665首次发表:更新:

AI 中文总结

研究针对代码优化中传统方法不适用于动态语言及现有大语言模型优化存在的问题,提出基于混合提示架构的Optimo方法,能在多个抽象层次优化代码,在不同代码基准测试中表现优异,大幅提升代码效率。

AI 中文摘要

运行时效率是影响软件质量和用户满意度的关键因素。传统代码优化方法对静态语言编译时的中间表示进行操作,难以处理动态语言。近期利用大语言模型直接优化动态语言源代码,但存在无法识别合适优化目标及单级优化不全面的问题。为此提出Optimo,基于混合提示架构的多级代码优化方法。通过差分分析识别关键代码结构,路由至特定优化策略。在两个代码效率基准上评估,结果表明Optimo优化人工编写代码时,opt%高达57.48%,加速比达3.97倍;优化大语言模型生成代码时,opt%达42.42%,加速比达13.51倍,且在opt%方面始终比最佳基线高出96.51%。

英文摘要

Runtime efficiency is a critical factor that impacts both software quality and user satisfaction. There are many approaches proposed for code optimization to improve runtime efficiency. Traditional code optimization methods operate on intermediate representations (IRs) during compilation for static languages. They are effective but struggle to handle dynamic languages that do not require compilation. Recently, large language models (LLMs) have been leveraged to directly optimize source code in dynamic languages. However, these methods fail to identify suitable optimization targets and usually conduct incomprehensive single-level optimization. To address these challenges, we propose Optimo, a multi-level LLM-based code optimization approach built on a novel Mixture-of-Prompts (MoP) architecture. In the MoP architecture, Optimo identifies time-critical code structures as performance bottlenecks via differential profiling. These structures are then routed to some optimization strategies, akin to expert models in MoE, each tailored to optimize specific code patterns. Unlike traditional approaches that focus only on statement-level optimizations, Optimo operates at four levels of abstraction, ranging from coarse-grained algorithmic improvements to fine-grained optimizations in API usage. We evaluate Optimo on two code efficiency benchmarks, COFFE and Effibench. Our results demonstrate that Optimo achieves an up to 57.48% opt%, i.e., the percentage of optimized programs that are correct and at least 10% faster than the original programs, and an up to 3.97x speedup when optimizing human-written code, and it consistently outperforms the best baseline by up to 96.51% in terms of opt%. Furthermore, Optimo achieves an up to 42.42% opt% and an up to 13.51x speedup when optimizing LLM-generated code.

CommentsThis paper has been accepted by ASE 2026

论文原文

arXiv 摘要页 · PDF 原文 · HTML 原文

↑