Reuse or Generate? Accelerating Code Editing via Edit-Oriented Speculative Decoding

Peiding Wang, Li Zhang, Fang Liu, Yinghao Zhu, Wang Xu, Lin Shi, Xiaoli Lian, Minxiao Li, Bo Shen, An FuarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) have revolutionized software development, yet their autoregressive nature often leads to significant latency during code editing tasks. This paper introduces EFFICIENTEDIT, a novel framework that accelerates code editing by up to 13x without compromising code quality. By recognizing that edited code typically reuses approximately 70% of the original snippet, EFFICIENTEDIT employs a "Reuse-Generate" paradigm. It utilizes the original code as a zero-cost draft for speculative decoding to skip unchanged sections and switches to a specialized, entropy-aware draft model to generate new code. Evaluations on the CanItEdit and CodeIF-Bench benchmarks demonstrate that EFFICIENTEDIT significantly outperforms existing state-of-the-art acceleration techniques.

Introduction

LLMs like GPT-4 and DeepSeek-Coder are now essential for tasks ranging from refactoring to bug fixing. However, generating code one token at a time is computationally expensive and slow, especially for large files. While standard speculative decoding—using a smaller model to guess tokens for a larger model to verify—helps in general text generation, it often fails to exploit the inherent structure of code editing. In editing scenarios, the majority of the output is already present in the input. EFFICIENTEDIT addresses this by treating the "Code Before" as a high-quality draft, effectively solving the "where to edit" and "what to keep" problems simultaneously.

Methodology: The Reuse-Generate Paradigm

EFFICIENTEDIT operates through a two-phase process designed to maximize efficiency by distinguishing between reused and newly generated code.

1. The Reuse Phase

Instead of relying on a draft model to predict every token, EFFICIENTEDIT uses the original code as the draft. The target LLM verifies large blocks of this original code in a single forward pass. When the target model rejects a token, it naturally identifies an "edit location" without the need for additional search algorithms.

2. The Generate Phase

Once an edit point is reached, the system transitions to a specialized draft model. This phase is enhanced by two key innovations:

  • Edit-Oriented Fine-Tuning: Draft models (e.g., Qwen2.5-Coder-7B) are fine-tuned specifically on code changes, with reused parts masked during training. This specialization allows the draft model to excel at predicting edits rather than general code structure.
  • Entropy-Aware Dynamic Verification: To avoid the over-conservatism of strict greedy matching, EFFICIENTEDIT uses the target model's confidence (entropy) to adjust verification. If the target model is uncertain, it accepts draft tokens that appear within its top-$k$ results, balancing speed with logical correctness.
The EFFICIENTEDIT framework illustrating the Reuse and Generate phases alongside specialized fine-tuning and verification strategies.

Experimental Setup

The framework was trained using InstructCoder, a dataset of 110,000 instruction-code triples. Evaluation was conducted on two primary benchmarks:

  • CanItEdit: 105 Python editing tasks covering corrective, refinement, and adaptive edits.
  • CodeIF-Bench: A complex benchmark featuring 762 real-world software editing problems across function and repository levels.

Key Results

EFFICIENTEDIT demonstrates substantial performance gains over standard autoregressive (AR) decoding and previous state-of-the-art methods like FastFixer.

Performance comparison of EFFICIENTEDIT against standard autoregressive (AR) decoding and other speculative methods across multiple benchmarks.

As shown in the results, EFFICIENTEDIT achieved a 10.38x speedup on CanItEdit and a 13.09x speedup on CodeIF-Bench when paired with DeepSeek-Coder-33B. Notably, it outperformed FastFixer by up to 90.6% in terms of throughput (tokens per second). Furthermore, the "soft" verification strategy often maintained or even improved the Pass@1 score, suggesting that the specialized draft model provides high-quality local completions that the target model finds acceptable.

Conclusion and Future Work

EFFICIENTEDIT provides a highly efficient solution for LLM-based code editing by leveraging the "free" draft provided by the original code. While the framework requires significant VRAM to host both target and draft models, its ability to drastically reduce latency makes it a powerful tool for developer productivity. Future research may explore smaller, more specialized draft models or the integration of retrieval-based drafting to handle massive, multi-file repositories where reuse occurs across different files.

Summary updated

BibTeX
@misc{wang2025reuse,
  author = {Peiding Wang and Li Zhang and Fang Liu and Yinghao Zhu and Wang Xu and Lin Shi and Xiaoli Lian and Minxiao Li and Bo Shen and An Fu},
  title = {{Reuse or Generate? Accelerating Code Editing via Edit-Oriented Speculative Decoding}},
  year = {2025},
  eprint = {2506.02780},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.02780},
}
Figure