用性能原因指导代码优化,让大模型真正理解如何提速。
ECO: Enhanced Code Optimization via Performance-Aware Prompting for Code-LLMs
- 从快慢代码对中提取性能改进的根因与逻辑
- 生成最多7.81倍提速且保持正确性的优化代码
- 无需微调,可通用接入各类代码大模型
代码运行时优化——即重写代码以提升执行速度——仍具挑战性,因其需权衡算法与结构选择带来的性能影响。现有方法使用慢-快代码对作为优化引导,但此类方法模糊了性能提升的根本原因,常导致模型仅模仿表面模式而非真正理解性能推理。本文提出ECO框架,通过从参考慢-快代码对中提炼运行时优化指令(ROIs),每条ROI描述低效根源及性能提升的逻辑依据。针对输入代码,ECO并行运行符号化顾问进行瓶颈诊断,并检索相关ROIs,二者共同构建性能感知提示,为代码大模型提供可操作的优化指引。该提示具备模型无关性,无需微调,可直接前置至任意代码大模型输入。实证研究表明,使用ECO提示后,代码大模型生成高效代码的能力显著提升,在最小化正确性损失的前提下实现最高达7.81倍的加速。
原文摘要 · Abstract (English)
Code runtime optimization-the task of rewriting a given code to a faster one-remains challenging, as it requires reasoning about performance trade-offs involving algorithmic and structural choices. Recent approaches employ code-LLMs with slow-fast code pairs provided as optimization guidance, but such pair-based methods obscure the causal factors of performance gains and often lead to superficial pattern imitation rather than genuine performance reasoning. We introduce ECO, a performance-aware prompting framework for code optimization. ECO first distills runtime optimization instructions (ROIs) from reference slow-fast code pairs; Each ROI describes root causes of inefficiency and the rationales that drive performance improvements. For a given input code, ECO in parallel employs (i) a symbolic advisor to produce a bottleneck diagnosis tailored to the code, and (ii) an ROI retriever to return related ROIs. These two outputs are then composed into a performance-aware prompt, providing actionable guidance for code-LLMs. ECO's prompts are model-agnostic, require no fine-tuning, and can be easily prepended to any code-LLM prompt. Our empirical studies highlight that ECO prompting significantly improves code-LLMs' ability to generate efficient code, achieving speedups of up to 7.81x while minimizing correctness loss.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。