Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translation

📄 arXiv: 2606.17683v1 📥 PDF

作者: Longhui Zhang, Jiahao Wang, Chenhao Hu, Bingyu Liang, Jing Li, Min Zhang

分类: cs.CL, cs.PL

发布日期: 2026-06-16

备注: Accepted to ICML 2026


💡 一句话要点

提出SwiftTrans以解决LLM代码翻译的效率问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码翻译 大型语言模型 运行效率 多视角探索 差异感知选择 自动化编程 软件开发

📋 核心要点

  1. 现有的LLM翻译方法在程序运行效率上存在明显不足,翻译的代码通常运行速度较慢。
  2. SwiftTrans框架通过多视角探索和差异感知选择两个阶段,生成多样化的翻译候选并选择最佳方案。
  3. 在CodeNet、F2SBench和新引入的SwiftBench基准上,SwiftTrans在正确性和运行效率上均表现出显著提升。

📝 摘要(中文)

尽管大型语言模型(LLMs)在自动代码翻译系统的功能正确性方面取得了显著进展,但翻译程序的运行效率却相对被忽视。随着摩尔定律的减弱,运行效率已成为程序质量的重要组成部分。我们的初步研究表明,LLM翻译的程序通常运行速度慢于人类编写的程序,且仅通过提示工程无法解决此问题。因此,我们提出了SwiftTrans,一个包含两个关键阶段的代码翻译框架:多视角探索和差异感知选择。实验结果显示,SwiftTrans在正确性和运行效率上均取得了一致的提升。

🔬 方法详解

问题定义:本论文旨在解决LLM翻译代码的运行效率低下问题。现有方法在功能正确性上表现良好,但在运行效率方面却未能得到足够重视,导致LLM翻译的程序运行速度普遍慢于人类编写的代码。

核心思路:论文提出的SwiftTrans框架通过引入多视角探索和差异感知选择的策略,旨在生成多样化的翻译候选并通过比较选择最佳方案,从而提升翻译程序的运行效率。

技术框架:SwiftTrans框架分为两个主要阶段:第一阶段是多视角探索(MpTranslator),利用并行的上下文学习生成多样化的翻译候选;第二阶段是差异感知选择(DiffSelector),通过显式比较翻译之间的差异来识别最佳候选。

关键创新:本研究的关键创新在于引入了分层指导和序数指导,使得LLM能够更好地适应多视角探索和差异感知选择这两个核心组件。这一设计显著提升了翻译的质量和效率。

关键设计:在技术细节上,MpTranslator采用了并行上下文学习的方法,DiffSelector则通过比较翻译候选的差异来进行选择。此外,论文扩展了现有的基准测试,增加了新的基准SwiftBench,以支持对翻译程序运行效率的评估。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,SwiftTrans在CodeNet、F2SBench和SwiftBench基准上均实现了显著的性能提升。在正确性和运行效率方面,SwiftTrans的表现均优于现有的LLM翻译方法,展示了其在实际应用中的潜力。

🎯 应用场景

该研究的潜在应用领域包括软件开发、自动化测试和代码审查等。通过提升代码翻译的运行效率,SwiftTrans可以帮助开发者更快速地生成高效的代码,从而提高软件开发的整体效率和质量。未来,该框架有望在更多编程语言和复杂应用场景中得到应用。

📄 摘要(原文)

While large language models (LLMs) have greatly advanced the functional correctness of automated code translation systems, the runtime efficiency of translated programs has received comparatively little attention. With the waning of Moore's law, runtime efficiency has become increasingly important for program quality, alongside functional correctness. Our preliminary study reveals that LLM-translated programs often run slower than human-written ones, and this issue cannot be remedied through prompt engineering alone. Therefore, our work proposes SwiftTrans, a code translation framework comprising two key stages: (1) Multi-Perspective Exploration, where MpTranslator leverages parallel in-context learning (ICL) to generate diverse translation candidates; and (2) Difference-Aware Selection, where DiffSelector identifies the optimal candidate by explicitly comparing differences between translations. We further introduce Hierarchical Guidance for MpTranslator and Ordinal Guidance for DiffSelector, enabling LLMs to better adapt to these two core components. To support the evaluation of runtime efficiency in translated programs, we extend existing benchmarks, CodeNet and F2SBench, and introduce a new benchmark, SwiftBench. Experimental results across all three benchmarks show that SwiftTrans achieves consistent improvements in both correctness and runtime efficiency.