paperbot · PL 论文追踪

全部论文 待读 收藏

P2 The Hidden Cost of Readability: How Code Formatting Silently Consumes Your LLM Budget

可读性的隐藏成本:代码格式化如何悄然消耗你的 LLM 预算
ICSE Proceedings of the 2026 IEEE/ACM 48th International Conference on Software Engineering2026匹配度 2/10 · 该论文研究代码格式化元素对 LLM token 开销与补全性能的影响,属于以提升 LLM 效率为目标的实证研究,与用户核心方向(面向 ML/Agentic 程序的静态分析、LLM 辅助形式化验证、浮点程序分析、贝叶斯程序分析)没有实质交叉。虽然同在“机器学习与程序语言”标签下并使用代码数据,但不涉及对程序的分析、验证或语义建模,且研究目标本身即为 LLM 效率优化(接近用户明确不感兴趣的“以 LLM 为研究目标”的类型)。引用 21 inbox
Dangfeng Pan, Zhensu Sun, Cenyuan Zhang, David Lo, Xiaoning Du
crossref: 2026-09-12dblp: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:大规模实证表明移除代码格式化元素可平均减少 24.5% 输入 token,而 LLM 补全性能几乎不受影响。

源代码中的缩进、换行等格式化元素是为人类可读性服务的,但对按线性 token 序列处理代码的大语言模型(LLM)而言,这些元素并非必要,反而带来额外计算开销与更长的响应时间。为厘清格式化的作用,本文开展了一项大规模实证研究,在 Fill-in-the-Middle 代码补全任务上,覆盖 Java、Python、C++、C# 四种语言与十种商用及开源 LLM,系统分析移除格式化元素后的 token 数量与模型性能变化。结果表明,LLM 在格式化与未格式化代码上的表现基本持平,输入 token 平均减少 24.5%,输出 token 的减少可忽略不计,说明格式移除是一种切实可行的效率优化策略。进一步探索发现,通过提示(prompting)与微调可让输出代码长度最多缩短 36.1% 而不损害正确性。作者还实现了一个双向代码格式转换工具,可无缝集成到现有 LLM 推理流程中,兼顾人类可读性与 LLM 效率。

问题
代码格式化元素(缩进、换行等)对人类可读性有益,但对以 token 序列处理代码的 LLM 而言可能只是冗余开销,其在 LLM 任务中的作用与代价此前缺乏系统评估。
方法
在四种编程语言、十种商用与开源 LLM 上进行大规模 Fill-in-the-Middle 代码补全实验,对比移除格式化元素前后的输入/输出 token 数与补全性能,并探索提示与微调对输出代码长度的影响,进而实现双向代码格式转换工具。
评估
通过跨四种语言、十种 LLM 的大规模补全实验量化格式移除带来的 token 节省与性能变化,并验证提示与微调在保持正确性前提下将输出代码长度最多缩减 36.1%。
原文摘要(Abstract)

Source code is usually formatted with elements like indentation and newlines to improve readability for human developers. However, these visual aids do not seem to be beneficial for large language models (LLMs) in the same way since the code is processed as a linear sequence of tokens. Furthermore, these additional tokens can lead to increased computational costs and longer response times for LLMs. If such formatting elements are non-essential to LLMs, we can reduce such costs by removing them from the code. To figure out the role played by formatting elements, we conduct a comprehensive empirical study to evaluate the impact of code formatting on LLM performance and efficiency. Through large-scale experiments on Fill-in-the-Middle Code Completion tasks across four programming languages (Java, Python, C++, C#) and ten LLMs-including both commercial and open-source models-we systematically analyze token count and performance when formatting elements are removed. Key findings indicate that LLMs can maintain performance across formatted code and unformatted code, achieving an average input token reduction of 24.5% with negligible output token reductions. This makes code format removal a practical optimization strategy for improving LLM efficiency. Further exploration reveals that both prompting and fine-tuning LLMs can lead to significant reductions (up to 36.1%) in output code length without compromising correctness. To facilitate practical applications, we develop a bidirectional code transformation tool for format processing, which can be seamlessly integrated into existing LLM inference workflows, ensuring both human readability and LLM efficiency.

链接与引用

DOI 原文 · arXiv · DBLP

BibTeX
@inproceedings{abs-2508-13666,
  title = {The Hidden Cost of Readability: How Code Formatting Silently Consumes Your LLM Budget},
  author = {Dangfeng Pan and Zhensu Sun and Cenyuan Zhang and David Lo and Xiaoning Du},
  booktitle = {ICSE},
  year = {2026},
  doi = {10.1145/3744916.3764556}
}