Manuscript Offprint

arXiv:2609.05779

Diffs vs. Whole Files: An Empirical Comparison of Iterative Edit-Based and Direct Generation for Flutter/Dart Code Models

Andrej Andrejev

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large language models used for code editing can be trained and deployed in at least two distinct output regimes: direct generation, where the model emits the entire modified file in one shot, and iterative diff-based generation (“steps”), where the model emits a sequence of localized search/replace edits that are applied one at a time until the model signals completion or a step budget is exhausted. The diff-based regime is attractive because it mirrors how human developers edit code and because, in principle, it should require the model to generate far fewer tokens per turn. We train two code models — a 100M-parameter model trained from scratch (Rainbow-Pony-100M) and a fine-tuned Qwen2.5-Coder-0.5B (Hui et al., 2024) — in both regimes on a shared Flutter/Dart code-editing dataset, and evaluate all four resulting models (architecture × regime) on a held-out set of ≈1,790 tasks per model. We find that direct generation substantially outperforms iterative diff-based generation on every metric we measure — compilation/static-analysis pass rate, bits-per-byte, character-level similarity to the reference, and blinded LLM-judge ratings of goal fulfillment, correctness, and code quality — and that this gap persists even after controlling for task difficulty via a matched-ID comparison and even when restricting the comparison to code that compiles on both sides. We then look for the conditions under which the diff-based model does win, and find a single, architecture-independent mechanism: diff-based generation is competitive specifically on short, spatially localized edits (few required edit steps), and its category-level wins concentrate in exactly the two task categories — refactoring and error-handling/edge-case fixes — that independently have the lowest mean edit-step count in our dataset. We term this task locality and discuss its implications for when an edit-based training regime is and is not the right choice for a code-editing model.

1 Introduction

When a language model is asked to modify an existing source file, there are two natural ways to have it express the change. The first is to regenerate the entire file from scratch, conditioned on the original file and the instruction (direct generation). The second is to have the model emit a sequence of localized edits — typically in a search/replace or unified-diff format — that are mechanically applied to the original file (iterative or diff-based generation). Production coding agents and IDE-integrated tools overwhelmingly favor some variant of the second approach (Aider, ongoing), for reasons that are intuitive: a diff is shorter than a whole file, so it is cheaper to generate and less likely to silently corrupt code the model was never asked to touch; it also mirrors the unit of work a human reviewer actually looks at (a pull-request diff, not a whole-file rewrite).

This work is licensed under a Creative Commons Attribution 4.0 International License (CC BY 4.0).

Whether this intuition holds up as a training objective, rather than just an inference-time interface choice, is less settled. Recent work is mixed. LintSeq (Piterbarg et al., 2025) shows that training on synthetic edit sequences — decomposing a reference program into a chain of small, lint-error-free edits — improves downstream code-synthesis quality relative to training on the final program alone, arguing that edit sequences are a better curriculum, not just a better interface. Conversely, practical edit-format benchmarks (Aider, ongoing) report that diff-style formats increase the rate of malformed edits (edit the harness cannot apply at all) relative to whole-file replacement, especially for weaker models, trading a token-efficiency win for a reliability cost. Adaptive-format work (Cheng et al., 2026) goes further and argues that neither format is uniformly better — the right format is a property of the specific edit, and a model (or router) that can choose per-edit outperforms a model committed to either format across the board.

This paper is an empirical contribution to that question, run end-to-end on our own models rather than third-party benchmark leaderboards, on a single narrow but realistic domain: Flutter/Dart code editing. We train two architecturally very different models — a small transformer trained from scratch and a mid-size pretrained model fine-tuned for the task — each in both a direct and a steps (iterative diff-based) variant, holding the training data, tokenization pipeline, and evaluation harness fixed across all four resulting models. This within-domain, within-dataset design lets us isolate the effect of the output regime itself from the many confounds (different base models, different datasets, different edit-format syntax) that make cross-paper comparisons on this question difficult.

Contributions. We report four findings:

  1. Across both architectures, direct generation beats iterative diff-based generation by a wide margin on every metric we measure (Section 4.1), and the gap is not explained away by the diff-based model running out of its edit-step budget or by outright edit-application failures — the majority of diff-based failures occur in trajectories that completed normally (Section 4.2).

  2. The gap survives a matched-ID comparison that controls for the possibility that diff-based failures concentrate on intrinsically harder tasks (Section 4.4), and survives restricting the comparison to only the code that compiles on both sides, as independently confirmed by a blinded LLM judge scoring goal fulfillment, correctness, and code quality (Section 4.5).

  3. Despite the aggregate gap, there is a real and reproducible subset of tasks where the diff-based model wins on judge-rated quality, and this subset is not random: it concentrates heavily in short edit trajectories (Section 4.6).

  4. The category- and trajectory-length-based findings are not two separate phenomena: the two task categories where diff-based wins are overrepresented (refactoring and error-handling/edge-case fixes) are, independently, the two lowest mean-edit-step-count categories in the dataset for both architectures. We unify these into a single explanatory variable we call task locality (Section 4.7).