Large Language Models (LLMs) have shown remarkable capabilities in solving various programming tasks, such as code generation. However, their potential for code optimization, particularly in performance enhancement, remains largely unexplored. This paper investigates the capabilities of LLMs in optimizing code for minimal execution time, addressing a critical gap in current research. The recently proposed code optimization methods construct program optimization pairs based on iterative submissions from the same programmer for the same problem. However, this approach confines LLMs to local performance improvements, neglecting global algorithmic innovation. To overcome this limitation, we adopt a completely different perspective by reconstructing the optimization pairs into a problem-oriented approach. This allows for the integration of various ideas from multiple programmers tackling the same problem. Furthermore, we observe that code optimization presents greater challenges compared to code generation, often accompanied by "optimization tax". Recognizing the inherent trade-offs in correctness and efficiency, we introduce a novel anchor verification framework to mitigate this "optimization tax". Ultimately, the problem oriented perspective combined with the anchor verification framework significantly enhances both the correct optimization ratio and speedup to new levels.
翻译:大型语言模型(LLM)在解决各类编程任务(如代码生成)方面已展现出卓越能力。然而,其在代码优化,特别是性能提升方面的潜力仍很大程度上未被探索。本文研究了LLM在优化代码以实现最短执行时间方面的能力,填补了当前研究中的一个关键空白。近期提出的代码优化方法基于同一程序员针对同一问题的多次迭代提交构建程序优化对。然而,这种方法将LLM局限于局部性能改进,忽视了全局算法创新。为克服这一局限,我们采用了一种完全不同的视角,通过将优化对重构为面向问题的方法。这使得整合来自多位解决同一问题的程序员的不同想法成为可能。此外,我们观察到与代码生成相比,代码优化面临更大挑战,常伴随“优化代价”。认识到正确性与效率之间固有的权衡,我们引入了一种新颖的锚点验证框架以减轻这种“优化代价”。最终,面向问题的视角与锚点验证框架相结合,将正确优化比率与加速比双双提升至新的水平。