arXiv:2501.16692cs.SEcs.AI2025-01被引 1

用上下文感知的生成技术自动优化代码运行效率。

Optimizing Code Runtime Performance through Context-Aware Retrieval-Augmented Generation

  • 模仿程序员思维,结合历史代码与控制流图分析进行优化
  • 在常见可执行代码上使运行效率提升7.3%(相比GPT-4o)
  • 适合关注自动化代码优化的开发者与性能工程研究者

通过自动化代码优化提升软件性能具有广阔前景。尽管大语言模型(LLM)已有进展,但在深度程序分析方面仍存在明显短板。本研究提出AUTOPATCH,一种基于上下文学习的方法,使LLM能够自动生成优化代码。该方法受程序员学习与应用知识方式启发,包含三个核心组件:(1) 基于类比的框架,使模型优化行为贴近人类认知过程;(2) 统一整合历史代码示例与控制流图(CFG)分析,实现上下文感知学习;(3) 通过上下文提示自动生成优化代码的自动化流程。实验表明,在常见可执行代码上,AUTOPATCH相较于GPT-4o实现了7.3%的执行效率提升,展现出在自动化程序运行时优化中的巨大潜力。

原文摘要 · Abstract (English)

Optimizing software performance through automated code refinement offers a promising avenue for enhancing execution speed and efficiency. Despite recent advancements in LLMs, a significant gap remains in their ability to perform in-depth program analysis. This study introduces AUTOPATCH, an in-context learning approach designed to bridge this gap by enabling LLMs to automatically generate optimized code. Inspired by how programmers learn and apply knowledge to optimize software, AUTOPATCH incorporates three key components: (1) an analogy-driven framework to align LLM optimization with human cognitive processes, (2) a unified approach that integrates historical code examples and CFG analysis for context-aware learning, and (3) an automated pipeline for generating optimized code through in-context prompting. Experimental results demonstrate that AUTOPATCH achieves a 7.3% improvement in execution efficiency over GPT-4o across common generated executable code, highlighting its potential to advance automated program runtime optimization.

代码优化LLM应用性能提升

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。