arXiv:2604.27296cs.SEcs.CL2026-04ACL被引 1

改进代码编辑格式,让大模型更高效地生成修改。

To Diff or Not to Diff? Structure-Aware and Adaptive Output Formats for Efficient LLM-based Code Editing

论文配图:To Diff or Not to Diff? Structure-Aware and Adaptive Output Formats for Efficient LLM-based Code Editing
图 1 · 摘自论文原文
  • 提出块级和函数级结构化差异格式,提升生成自然度。
  • 动态选择最优格式,长代码编辑降低30%延迟与成本。
  • 适合需要低延迟的交互式编程助手使用。

大型语言模型在代码编辑中应用日益广泛,但主流的全代码生成范式存在严重效率瓶颈,难以满足交互式编程助手对低延迟和低成本的要求。尽管模型能力持续扩展,编辑格式本身却未被充分重视。本文系统研究传统diff格式,发现脆弱的偏移量和碎片化补丁使生成过程对大模型极不自然。为此,提出BlockDiff和FuncDiff两种结构感知的diff格式,将修改表示为语法连贯单元(如控制结构、函数)的块级重写。进一步提出AdaEdit,一种通用自适应编辑策略,训练模型根据任务动态选择最节省令牌的格式(diff或全代码)。大量实验表明,搭配结构化diff格式时,AdaEdit在长代码编辑任务中准确率与全代码生成相当,同时延迟和成本均降低30%以上。

原文摘要 · Abstract (English)

Large Language Models (LLMs) are increasingly used for code editing, yet the prevalent full-code generation paradigm suffers from severe efficiency bottlenecks, posing challenges for interactive coding assistants that demand low latency and cost. Despite the predominant focus on scaling model capabilities, the edit format itself has been largely overlooked in model training. In this paper, we begin with a systematic study of conventional diff formats and reveal that fragile offsets and fragmented hunks make generation highly unnatural for LLMs. To address it, we introduce BlockDiff and FuncDiff, two structure-aware diff formats that represent changes as block-level rewrites of syntactically coherent units such as control structures and functions. Furthermore, we propose AdaEdit, a general adaptive edit strategy that trains LLMs to dynamically choose the most token-efficient format between a given diff format and full code. Extensive experiments demonstrate that AdaEdit paired with structure-aware diff formats consistently matches the accuracy of full-code generation, while reducing both latency and cost by over 30% on long-code editing tasks.

代码生成LLM优化编辑效率

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