Automated code optimization improves program performance through refactoring, and recent studies leverage LLMs for this purpose. Existing approaches mine optimization commits from open-source codebases to build large-scale knowledge bases, then employ retrieval techniques such as BM25 to obtain relevant examples for hotspot code, guiding LLMs in optimization. However, semantically equivalent optimizations often appear in syntactically dissimilar code, so current retrieval methods fail to identify pertinent examples, leading to suboptimal results. To address these limitations, we propose SemOpt, a framework that leverages static program analysis to identify code segments, retrieve optimization strategies, and generate optimized results. SemOpt has three LLM-powered components: (1) a strategy library builder that extracts and clusters strategies from code modifications, (2) a rule generator that produces Semgrep static analysis rules to capture each strategy's applicability, and (3) an optimizer that generates optimized code using the strategy library. On a benchmark of 151 C/C++ and 150 Python optimization tasks, SemOpt shows consistent improvements across different LLMs, increasing successful optimizations by 1.38 to 28 times on C/C++ and 4.60 to 6.33 times on Python versus the baseline. On large-scale projects, SemOpt improves performance metrics by 5.04% to 218.07% on C/C++ and 61.77% to 479.90% on Python, showing cross-language generalization and practical effectiveness.


翻译:自动化代码优化通过重构提升程序性能,近年研究利用大语言模型(LLM)实现该目标。现有方法从开源代码库中挖掘优化提交记录以构建大规模知识库,再采用BM25等检索技术为热点代码获取相关示例,进而指导LLM进行优化。然而,语义等价的优化常出现在语法不同的代码中,当前检索方法难以识别相关示例,导致优化效果欠佳。针对上述局限,本文提出SemOpt框架,通过静态程序分析识别代码片段、检索优化策略并生成优化结果。SemOpt包含三个基于LLM的组件:(1) 策略库构建器,从代码修改中提取并聚类优化策略;(2) 规则生成器,为Semgrep静态分析规则生成器以捕获各策略的适用场景;(3) 优化器,利用策略库生成优化代码。在包含151个C/C++和150个Python优化任务基准测试中,SemOpt在不同LLM上均取得显著改进:与基准方法相比,C/C++任务的成功优化次数提升1.38至28倍,Python任务提升4.60至6.33倍。在大型项目中,SemOpt使C/C++性能指标提升5.04%至218.07%,Python提升61.77%至479.90%,展现了跨语言泛化能力与实用有效性。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
【优博微展2019】李志泽:简单快速的机器学习优化方法
清华大学研究生教育
15+阅读 · 2019年10月8日
以BERT为例,如何优化机器学习模型性能?
专知
10+阅读 · 2019年10月3日
机器学习中的最优化算法总结
人工智能前沿讲习班
22+阅读 · 2019年3月22日
超全总结:神经网络加速之量化模型 | 附带代码
干货|当深度学习遇见自动文本摘要,seq2seq+attention
机器学习算法与Python学习
10+阅读 · 2018年5月28日
【干货】深入理解自编码器(附代码实现)
从浅层模型到深度模型:概览机器学习优化算法
机器之心
27+阅读 · 2017年7月9日
国家自然科学基金
2+阅读 · 2017年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
VIP会员
最新内容
学习数据的几何:形状空间分析数学综述
专知会员服务
6+阅读 · 6月17日
定向能反无人机系统最新发展动态
专知会员服务
7+阅读 · 6月17日
从燃煤战舰到算法战争:水面指挥的永恒要求
专知会员服务
4+阅读 · 6月17日
相关VIP内容
相关资讯
【优博微展2019】李志泽:简单快速的机器学习优化方法
清华大学研究生教育
15+阅读 · 2019年10月8日
以BERT为例,如何优化机器学习模型性能?
专知
10+阅读 · 2019年10月3日
机器学习中的最优化算法总结
人工智能前沿讲习班
22+阅读 · 2019年3月22日
超全总结:神经网络加速之量化模型 | 附带代码
干货|当深度学习遇见自动文本摘要,seq2seq+attention
机器学习算法与Python学习
10+阅读 · 2018年5月28日
【干货】深入理解自编码器(附代码实现)
从浅层模型到深度模型:概览机器学习优化算法
机器之心
27+阅读 · 2017年7月9日
相关基金
国家自然科学基金
2+阅读 · 2017年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员